Jump to content

including a file across multiple pages...


tefuzz

Recommended Posts

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 ;)

Link to comment
https://forums.phpfreaks.com/topic/146277-including-a-file-across-multiple-pages/
Share on other sites

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.

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

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

I run the whole site off index.php, and just switch out data where it's needed :D.

 

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.

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.