General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 19th, 2003, 04:32 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
Arrow Making a global config file for a script?

Let's say I make a file like conf_global.php which contains the following:

PHP Code:
 $INFO['admin_group']            =    '4';
$INFO['allow_creator_vote']            =    '1';
$INFO['allow_dup_email']            =    '0';
$INFO['allow_dynamic_img']            =    '0';
$INFO['allow_flash']            =    '0';
$INFO['allow_images']            =    '1';
$INFO['allow_online_list']            =    '1';
$INFO['allow_result_view']            =    '0';
$INFO['allow_search']            =    '1';
$INFO['allow_skins']            =    '1';
$INFO['auth_group']            =    '1'


Basically it's a file containing global settings for my script. How would I use those vars on the rest of my script? Would just including the conf_global.php work?
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #2  
Old December 19th, 2003, 08:14 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Yes, a simple include should work. If you need to use the variables in functions within the other scripts, you could either pass the array (or values) to the function or declare them global within each relevant function. Another approach is to build an object with set and get methods for various options and instantiate the object in each relevant page. This also makes it easy for you to have functions common to a bunch of files that can operate easily on the config options.

Reply With Quote
  #3  
Old December 19th, 2003, 08:47 PM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
if i include the file in the beginning of my script and just set 'global $myvar' right after making my class can i use it in all my functions?

Reply With Quote
  #4  
Old December 22nd, 2003, 09:39 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
I believe you'd have to declare $myvar global within all functions. Using globals is typically considered bad practice. Better to pass as a param, in my opinion.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Making a global config file for a script?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT