I'm at the very low-end of the totem pole when it comes to PHP programming and I'm finding myself stuck on a simple include. Let's say I have a file at http://www.mysite.com/1/2/test.php. In this file I want to be able to echo some variable, so the only code in the file is: <?php echo $variable; ?> Now, I want to include this variable from another file that will hold all variables; let's call it config.php. That file is located at http://www.mysite.com/3/4/config.php. When I add this code to the top of test.php to include the file I get no output: <?php include("http://www.mysite.com/3/4/config.php"); ?> And, of course, when I throw the config file into the same directory as test.php and call it as: <?php include 'config.php'; ?> the output is perfect. So, assuming the above makes sense, my problem is that I'm not able to pass my variables via the URL include. I need an easy way to store a bunch of variables in one file and include that variables file on many other pages, spread over the structure of the site, preferably via an URL include. So: is this possible or is there an even better alternative? Thanks in advance!
You should use relative paths in include and require procedures. Instead of include("http://smth.tld/include.php"); use include("./include.php"); I found a better alternative to use external php files in your script with the procedure readfile . I didn't work with it, but you can read about it on php.net.
Thanks for the info! I understand now that this is a parsing problem - a bit of experimenting lead me to use absolute paths so I think I'll stick with that far now but I'll definitely look into the readfile function
Yes, you have to rememer that php is server side code. Therefore it takes on the perspective of the server it is running on. A URL (http://) is a client side request. So in php you have to use ./ (same directory) or ../ (one directory back) as that is how the server relates things.
Now you could do what you wanted to do but you need to use things like file_get_contents and then http is acceptable.
But even then, if your host has locked down fopen to not allow http:// requests, it will still fail. Alot of places I've seen have disabled http fopens, due the number of scripts that were written poorly and could be exploited via it.
use a relative link. so have all the variables defined in say config.php and on each page just use include("config.php");