Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/276315-help-with-new-php-version/
Share on other sites

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?

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

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

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.

Warning

Windows 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 warning

Remote 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.

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.

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!

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

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

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?

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.