tefuzz Posted February 21, 2009 Share Posted February 21, 2009 i have just begun to dabble in php and the first thing i am trying to tackle is getting certain variables available on any page the user visits..must i have (see below) at the top of every file or is there away to make it so that no matter what page the viewer is on the variables defined in test.php are available? is this a session issue, am i getting over my head or...? <?php include('test.php'); ?> thanks for helping a noob Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 21, 2009 Share Posted February 21, 2009 You could define in your php configuration to auto include files, but that's not very portable. It's best just to include it on every page, because in the future you may very well not want it on a certain page and it will be a pain to fix that problem if you told the server to auto include it. Quote Link to comment Share on other sites More sharing options...
tefuzz Posted February 22, 2009 Author Share Posted February 22, 2009 I'm curious how to use a file in all pages on a website without using an include or require line at the beginning of every page...basically i'm looking to have a single index page be template driven, but if the user moves to another page maintain the template, and be able to access any function on any page. kind of like how when using wordpress, you enter the database info into the config file, and no matter what page you are on it can still connect to the database Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 22, 2009 Share Posted February 22, 2009 If you insist you wish to do it, despite the belief that it's not a good thing (even your example, wordpress, uses include()s and require()s, not auto inclusions) you can look into the auto_prepend_file php.ini directive... http://us2.php.net/ini.core Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 22, 2009 Share Posted February 22, 2009 I run the whole site off index.php, and just switch out data where it's needed . Quote Link to comment Share on other sites More sharing options...
tefuzz Posted February 22, 2009 Author Share Posted February 22, 2009 I run the whole site off index.php, and just switch out data where it's needed . ok so something like this, i was just discussing this in another thread (http://www.phpfreaks.com/forums/index.php/topic,239825.0.html) is this kinda the same scenario?. a user clicks a link, and there's a value passed like 'index.php?action=contact' and you would load the contact data into the page upon reloading? i was thinking of having the same thing for my site to keep are there any examples of this around? and what exactly is this called? how would i search for it say, on Google? does this use an outside functions page and config so that on reload it would call the right function which would load the right page data? am i getting over my head for a beginner with something like this? it doesn't seem all that hard, but im sure it's more than what it looks. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 22, 2009 Share Posted February 22, 2009 just done a example here >>> http://www.phpfreaks.com/forums/index.php/topic,239842.0.html Quote Link to comment Share on other sites More sharing options...
tefuzz Posted February 22, 2009 Author Share Posted February 22, 2009 just done a example here >>> http://www.phpfreaks.com/forums/index.php/topic,239842.0.html Using that wouldn't it be a gigantic file size to include all of the possible cases? I mean. if i had index.php?action=contact and then have the entire contact page code after it? if i had 8 different links at the top and then had 8 different sets of data below it that could possibly be loaded. Is it that involved/difficult to make it call a function like get_contact(); which would load the contents of contact.php and place it into the page for you? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.