Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- From: "Paul D. Kilbot" <kilbotNO@xxxxxxxxxxxxxxx>
- Date: Mon, 18 Apr 2005 23:31:21 +1000
Oli Filth wrote:
Paul D. Kilbot wrote:
Hi there,
I had dealt with the strangest error today and I'm hoping someone might be able to shed some light on the matter..
I was using the session 'page' to store the current page, ie:
<?php session_start(); header("Cache-control: private"); // IE 6 Fix.
$_SESSION['page'] = $_SERVER['PHP_SELF']; ?>
And then using $_SESSION['page'] for login and logout scripts so that the user would be returned back to the page they were viewing. Everything worked fine on IE and firefox..
Then my client wanted a custom 404 error page so I added the following to the .htaccess file
ErrorDocument 404 /404.php
The 404 custom page worked fine, but now $_SESSION['page'] = $_SERVER['PHP_SELF']; was stored as /404.php in firefox. And this is the weird bit, it still worked ok in IE.
I spent a couple of hours searching google and playing with the code and still couldn't find the problem.. then I downloaded LiveHTTPHeaders for firefox. Running my script I noticed that firefox was looking for the file /favicon.ico and when it couldn't find it was receiving a 404 error. I uploaded an empty file called favicon.ico to the root directory and suddenly the $_SESSION['page'] = $_SERVER['PHP_SELF']; behaves normally again...
So the script works, which is good, but I don't really understand why firefox had a problem and given my knowledge of php is pretty basic I'm wondering if I have missed something.
If anyone can explain this strange error/bug I would love to hear it..
As for why it only occurs in Firefox (and Opera and Mozilla and probably others), it's because IE doesn't request favicon.ico by default.
I can only reproduce this problem if I add the $_SESSION["page"] = $_SERVER["PHP_SELF"] line to 404.php. (which makes sense, cos the page script will have completed by the time favicon.ico is requested, so it can't possibly intefere directly)
Is this what you have (i.e. setting $_SESSION["page"] in 404.php)? If so, why would you want to do this in the error page?
Thanks for the quick reply Oli..
You were right, I had added
<?php
session_start();
header("Cache-control: private"); // IE 6 Fix.$_SESSION['page'] = $_SERVER['PHP_SELF'];
$uid = $_SESSION['uid']; $pwd = $_SESSION['pwd']; ?>
to all my files, including 404.php.. I removed this line and now my login/logout scripts work without the need for a favicon.ico file.
It all makes sense now :) (i think)...
So when displaying a page firefox would ask for favicon.ico, the server would dish up a 404 error and in doing so the $_SESSION['page'] would be reset as 404.php.
Of topic and probably a stupid question, but I notice you use double quote marks eg: $_SESSION["page"] and I have been using single quote marks.. my scripts have been working but should I change them?
Thanks again .
- Follow-Ups:
- Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- From: Oli Filth
- Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- References:
- $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- From: Paul D. Kilbot
- Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- From: Oli Filth
- $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- Prev by Date: Re: Session timeouts & checking when a session has died
- Next by Date: Re: parsing html in php
- Previous by thread: Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- Next by thread: Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error
- Index(es):
Relevant Pages
|