Forum Moderators: phranque
<?php
session_start();
?>
<br /><img src="aaa.jpg" alt="" height="30" width="90" /><br />
<?php
$_SESSION['page'] = $_SERVER["PHP_SELF"];
echo $_SESSION['page'];
?> <?php
session_start();
echo $_SESSION['page'];
?> Running the first page gives the output 'test.php' which is correct, but when I run the second page the output is 'error.php'.
You want to be looking at the requested URL as seen from the web, not at the filename that was pulled from the hard drive to satisfy that request.
Does it do this all the time, or only if you run it immediately after the first page? (Implying that it's sending back your starting point, rather than your ending point.)
Does "$_SERVER["PHP_SELF"]" return the public URL or your current physical location? The "SERVER" element makes me uneasy, though technically it may not make any difference if you're only using the information behind the scenes.
Oh, and stop saying "404 redirect" ;) You know what you mean and we know what you mean, but it's still wrong. And what's it doing messing about with 404s for images? It would drive me bonkers. I mean, your page isn't showing a thumbnail of the custom 404 page in the place where the image ought to be.
Just out of curiosity. For testing only; don't keep it for the live site. What happens if you have a different function for nonexistent image files? That is, something involving mod_rewrite, a Rule for (jpe?g|gif) etc, and !-f ? Do you then get the name of your regular 404 document, or the name of the "ain't no such picture" document?
<FilesMatch "\.(jpe?g|gif|png|bmp|ico)$">
ErrorDocument 404 "File Not Found"
</FilesMatch>