howard-moore Posted March 30, 2013 Share Posted March 30, 2013 Hi All,I have recently upgraded my PHP server version to 5.4.12, and I am having some real difficulties with getting something to work.The issue is with includes. I have a folder/file display script which I need to include into a pretty standard PHP page, and in 4.x it worked fine <?php include ("$domain/docs/index.php?dir=".urlencode($dir)); ?> However, I cannot get anything in that directory (/docs) to show at all. When I roll back the server version to 4.x it works, but in 5.4.12 it doesn't.I have read through the changes in PHP4-5, but cannot find anything about this. Can someone recommend a change that would enable it to work?Thanks,Neil Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/ Share on other sites More sharing options...
howard-moore Posted March 30, 2013 Author Share Posted March 30, 2013 OK, so I have managed to get some of it to work by using the following: <?php echo (file_get_contents("$domain/docs/index.php?dir=".urlencode($dir))); ?> However, the purpose of dir=".urlencode($dir) is that it is meant to display the directory that you have clicked on, but file_get_contents does not do this in the same way as include. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1421924 Share on other sites More sharing options...
PaulRyan Posted March 30, 2013 Share Posted March 30, 2013 What does $domain and $dir contain? Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1421925 Share on other sites More sharing options...
howard-moore Posted March 30, 2013 Author Share Posted March 30, 2013 $domain is just my website domain (to save typing it out again and again), and $dir is the directory that the script at docs/index.php is looking at. When you click into a the directory it lists other directories or files that are in there. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1421926 Share on other sites More sharing options...
howard-moore Posted March 30, 2013 Author Share Posted March 30, 2013 I have managed to change the php.ini file so that allow_url_include is now on, but the ?dir=".urlencode($dir) part is still not working. It is only showing the first directory.The idea of the code is that when you click through to a sub-directory, the url will be something like:domain/documents.php?dir=Sub Folder&order_by=date&order=asc It would then show the contents of the Sub Folder. It works fine in php 4.4.9, so I don't know what the include should look like now.Do you know if anything else in the php.ini needs to be changed to allow that, or do I need to change include ("$domain/docs/index.php?dir=".urlencode($dir));? Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1421930 Share on other sites More sharing options...
SurvivorZ Posted March 30, 2013 Share Posted March 30, 2013 You should use include to fetch files from your web server's file system. NOT URLs. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1421947 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 You should use include to fetch files from your web server's file system. NOT URLs. OK thanks. However, does anyone know why the urlencode element works in PHP 4.4.9 and not 5.4.12? I have the include part working, but not the dynamic bit on the end: <?php include ("$domain/docs/index.php?dir=".urlencode($dir)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422062 Share on other sites More sharing options...
jcbones Posted March 31, 2013 Share Posted March 31, 2013 include If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Supported Protocols and Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script. WarningWindows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled. Warning Security warningRemote file may be processed at the remote server (depending on the file extension and the fact if the remote server runs PHP or not) but it still has to produce a valid PHP script because it will be processed at the local server. If the file from the remote server should be processed there and outputted only, readfile() is much better function to use. Otherwise, special care should be taken to secure the remote script to produce a valid and desired code. Perhaps they turned it back off. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422065 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 include Perhaps they turned it back off. Thanks for the reply. However, the include part is now working - the only bit that doesn't work now is the urlencode($dir) part. The way this works in 4.4.9 is that when a user clicks on a particular directory (e.g. ../docs/index.php?dir=Sub Folder) the include shows the contents of that sub-folder through the page that the user is on (e.g. ../documents.php). I could go back and recode everything so that the code at ../docs/index.php is all in documents.php, but I have hundreds of sites all using the same process, and it will take days and days of recoding to get it all done this way. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422067 Share on other sites More sharing options...
PaulRyan Posted March 31, 2013 Share Posted March 31, 2013 Well it would be better to recode and have this all working properly and for it work to in future PHP versions, than just finding the "easy way" out of this. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422075 Share on other sites More sharing options...
mac_gyver Posted March 31, 2013 Share Posted March 31, 2013 the parameters on the url most likely don't work because your code in the requested file is dependent on register_globals and needs to be fixed to use $_GET['dir'] Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422086 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 the parameters on the url most likely don't work because your code in the requested file is dependent on register_globals and needs to be fixed to use $_GET['dir'] This is really interesting, but I'm not sure I completely understand. I'm afraid I don't really know much about register_globals, and what needs to be changed. Could you explain what this does? Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422091 Share on other sites More sharing options...
mac_gyver Posted March 31, 2013 Share Posted March 31, 2013 you need to find out if this is what is causing the problem. is your code using $dir or $_GET['dir'] to access the value from the url? Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422093 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 you need to find out if this is what is causing the problem. is your code using $dir or $_GET['dir'] to access the value from the url? OK - I've looked through the code at ../docs/index.php and it is using $_GET['dir']. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422102 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 Actually, I've just noticed another one using the new PHP 5.4.12 version, which I am sure is related. I have the following code: <? include ("content/content_news$template.php"); ?> and the idea is when you are www.domain.com/news.php?template=2 it would show ../content/content_news2.php. However, it is ignoring this and just showing template #1. This is clearly the same issue that I am having above, and I have hundreds of sites that I would need to recode if I can't find a fix to get this working under 5.4.12. Any ideas? Thanks,Neil Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422105 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 OK, so I've done some testing with another site and tried turning off register_globals, and this brings up exactly the same results. Therefore, this is what is causing the problem. Does anyone know how to replicate what register_globals does when running 5.4.12? I can't begin to tell you how many months of work it will be to recode everything if it can't be done!!! Thanks (in hope!),Neil Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422110 Share on other sites More sharing options...
kicken Posted March 31, 2013 Share Posted March 31, 2013 http://php.net/extract. However, you really need to fix the code, not just apply a band-aid solution. register_globals was removed for a reason, it is insecure and can lead to a number of issues. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422113 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 Thanks, but I have absolutely no idea what to do with extract? I appreciate that I will need to rewrite the code, and I have instructed someone to do that for me for the next build of the core code that I use, but in the meantime unfortunately it will take far, far too long to change all the other sites running it (there are hundreds of them!). Is there not something I can change in the php.ini file to allow this to work? Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422118 Share on other sites More sharing options...
kicken Posted March 31, 2013 Share Posted March 31, 2013 Is there not something I can change in the php.ini file to allow this to work?No, the setting has been removed, not just disabled. The functionality you were using no longer exists. You could always just downgrade back to an older version of PHP if you're that desperate to get it back. Then work on your scripts to fix the problem and upgrade again a few months from now. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422122 Share on other sites More sharing options...
howard-moore Posted March 31, 2013 Author Share Posted March 31, 2013 Thanks for the heads-up for this. Unfortunately my server host is telling me that they are no longer going to allow the downgrade to older versions (only 5.4), so I guess I have a busy few weeks ahead!! Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422129 Share on other sites More sharing options...
mac_gyver Posted March 31, 2013 Share Posted March 31, 2013 register_globals were turned off by default in 2002 having been superseded by the $_GET/POST... variables. there has been plenty of time for coders learn how and to stop writing new code that used them and to update any existing code. no one should be surprised or still have any affected code in 2013 when this depreciated feature was finally removed in php5.4. Quote Link to comment https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/#findComment-1422142 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.