Jump to content

Recommended Posts

I have this variable:

 

$myPage = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

 

I would pass this into another function which would then read the index.php and parse it

 

I've had my server moved to newer hardware within the same hosting company

The PHP version is the next one up

 

Now my script doesn't work    :(

 

I've now found that I need to specifically give the index.php as a filename, i.e.:

 

$pageToPreview = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';

 

The problem is that I have thousands of instances where I use the original version

 

Is there an environment setting somewhere that is causing me a problem?

 

The last version of PHP I would have had would have been quite recent andnot ancient - it would have been something like 5.25

Is the upgrade of the PHP the cause of the problem?

 

Thanks

 

 

OM

 

 

From the PHP documentation at http://www.php.net/manual/en/reserved.variables.server.php

 

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those.

 

What that means is it's due to the web server configuration by your host.  And it also means that PHP makes no guarantees about the contents of PHP_SELF, so it's up to you to deal with it.

 

As for the specific problem, try printing out the value of $_SERVER['PHP_SELF'] before applying dirname().  It's likely that it already contains the value you want, and that dirname() is actually removing the index.php from the end.  It would have worked before because it had a "/" character at the end.  That's my guess.

 

As for how many places you need to change this in, consider it a lesson in why you shouldn't copy and paste code - if you had this variable defined in one central location and then referenced in other scripts, you would only need to change it once.

What that means is it's due to the web server configuration by your host.  And it also means that PHP makes no guarantees about the contents of PHP_SELF, so it's up to you to deal with it.

 

As for the specific problem, try printing out the value of $_SERVER['PHP_SELF'] before applying dirname().  It's likely that it already contains the value you want, and that dirname() is actually removing the index.php from the end.  It would have worked before because it had a "/" character at the end.  That's my guess.

 

As for how many places you need to change this in, consider it a lesson in why you shouldn't copy and paste code - if you had this variable defined in one central location and then referenced in other scripts, you would only need to change it once.

thanks for the reply - that's great advice

your right on all counts

yes: lesson learned

 

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.