Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php_self

Options
  • 01-05-2013 7:41pm
    #1
    Registered Users Posts: 1,002 ✭✭✭


    I had a piece of PHP successfully running on a site for quite a while until the owner moved service provider. Now the PHP has stopped working sort of.

    If the page was called for example contactus.php then a specific image was displayed otherwise a default image was shown.

    Currently the last echo is getting executed. If I rename defaultimage then the image that is displayed is broken. So I know that line is being executed.
    But the $PHP_Self == ' ' is getting ignored.

    The site is configured for PHP4. I don't know a whole lot about PHP, so kinda stuck. :o
    <?
    		if ($PHP_SELF == 'index.php')
    		{
    		echo ('<img src="indeximage.gif" width="100" height="100">');
    		}
    		elseif ($PHP_SELF == 'contactus.php')
    		{
    		echo ('<img src="contactusimage.gif" width="100" height="100">');
    		}	
    		else
    		{
    		echo ('<img src="defaultimage.gif" width="100" height="100">');
    		}
    	?>
    


Comments

  • Registered Users Posts: 139 ✭✭Bald? er, dash!


    Its probably that your old server had register_globals on in php.ini, which is now not the case with the new server.

    Anyway, you can access the same information from using the $_SERVER, however, this will return the path relative to the root, so as a minimum you should add a / before the filename (i.e. /index.php), or if they are in a sub-directory of the root, /directory/index.php

    This should do the trick:
    [PHP]
    <?
    if ($_SERVER == '/index.php')
    {
    echo ('<img src="indeximage.gif" width="100" height="100">');
    }
    elseif ($_SERVER == '/contactus.php')
    {
    echo ('<img src="contactusimage.gif" width="100" height="100">');
    }
    else
    {
    echo ('<img src="defaultimage.gif" width="100" height="100">');
    }
    ?>
    [/PHP]


  • Registered Users Posts: 1,002 ✭✭✭MargeS


    Thanks Bald? er, dash!
    I get it now. I had managed to figure out the global variables part and was reading up on that. I thought that php_self would give me just the file name after the domain without /


Advertisement