So, I just got a programmer to write a great mapping script for one of my sites. His code requires PHP5 for some of the functions which it uses. This seemed like no problem, but when I switched over, it has broken some of the nested includes on some of my PHP pages. I think I have identified the issue. For PHP5, my server does not allow full URL references: so, include("http://www.site.com/file.php"); has to be include("file.php"); for security concerns. I've decided it would be best to replace the full references and start doing it the 'proper' way with relative references; however, I have noticed a very odd impact...I now have variable dependencies that were not there before. I tend to use very common naming conventions in my different files which are often the same ($i, $row, $sql_query, etc). This was never a problem before, it actually helped w/ code re-use, but now it seems to be a major issue. So, for example, below is a scenario where this messes things up: <?php $i = "what i want to print"; // an include of file.php is called which might be a common file i use a lot but which also creates an $i variable which is different than above include("file.php"); // the code now prints the $i from file.php rather than the one called above, which never happened with the full URL include reference path echo $i; ?> This is not an exact example, as what I'm dealing with is much more complex, but it should give you the idea. Basically, a full URL reference seems to parse the code before brining it in, whereas a relative reference seems to bring in the code and then parse it. This is a subtle difference, but one that impacts much of the code on my site. Any ideas of how I can either parse the relative include files before bringing them in or use other functions so that I don't have to majorly re-write a ton of my code? Thanks!
I think you will need to rewrite your code, sorry. PHP takes the latest variable declaration, and once you include a file that has $i, it will save that instead of the one above it.
I should only need output, so that might work. I can't seem to get fopen to do anything... When I do fopen("file.php","r"); it seems to return nothing...even for standard html files w/ no php...ie fopen("text.hml","r"); Any ideas as to what parameter to use or as to why it would return nothing when the include works (even when it's just standard html)? What's the main difference between fopen and include?
If you want to include files using http then you will need to go into your php file and set allow_url_fopen to on. This isn't a good approach though because you're opening a http connection for every file which puts unnecessary load on your webserver, ideally your programmer would have known this. As for your variables, maybe you can use different naming conventions. Traditionally $i is only used for counters and loops. In your case, fopen won't read any contents, it just creates a handler that you CAN use to read the contents... Try this instead: $output = file_get_contents('file.php'); The differences are that include parses the php inside a file. file_get_contents actually reads the contents of the file so you'll actually have the php code inside $output. Hope this helps
Just use full url path, actually you must use full path if you only want the code output. Try this actually (file_get_contents should be suited better for what you want): $include_content = file_get_contents("http://www.site.com/file.php"); echo $include_content; Code (markup): If that doesn't work, you could always use cUrl.
I do need it to parse before bringing it in, which file_get_contents and fopen() don't seem to do for me. I might have to just suck it up and rewrite the code that I'm including to eliminate the variable redundancies.
I think that your fopen() is ok, otherwise PHP should output an E_WARNING notice !!! To allow PHP to fopen/include files on remote servers, you have to set allow_url_fopen/allow_url_include to 1 on your php.ini file