Re: $_SERVER['PHP_SELF'], ErrorDocument, Firefox error



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
.



Relevant Pages

  • Re: $_SERVER[PHP_SELF], ErrorDocument, Firefox error
    ... Everything worked fine on IE and firefox.. ... I uploaded an empty file called favicon.ico to the root directory ... 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. ... it's because IE doesn't request favicon.ico by default. ...
    (alt.php)
  • Re: Internet Explorer - Firefox
    ... Firefox, the problem is how publisher displayed it in IE. ... I imagine it is a problem with how the script is ... suppose to display a search box for flights..i am pretty sure that the ...
    (microsoft.public.publisher.webdesign)
  • RE: error script with music
    ... Try to Disable all Add-Ons for Firefox for now, you will bring it up later ... In the IE Propertise Go to the Programs Tab and Navigate to Manage Add-Ons ... "nass" wrote: ... Internet Explorer Script Error ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Generate a unique ID that identifies the client?
    ... for it not to be guessable by a robot. ... than this e.g. they can be used to track locations, ... Interesting that they can be obtained using a Firefox ... script - for now at least. ...
    (comp.lang.javascript)
  • Re: Tooltips ?
    ... they also need to be enabling script and ActiveX. ... :> You're in a client-side vbscript NG. ... :> Why would you even consider testing anything in Firefox from this NG? ... How do you know if someone coming to your site using a particular browser is ...
    (microsoft.public.scripting.vbscript)