Jump to content

Firefox double session


Doyley

Recommended Posts

Hi all,

 

I have a problem with a script using sessions on Firefox.

I am running the latest verion, but many others are having the same problem.

 

if (!isset($_SESSION['valid_fails'])) {
$_SESSION['valid_fails'] = 1;
} else {
$_SESSION['valid_fails']++;
}

 

It appears that the increment happens twice.

 

I found this on your site

 

http://www.phpfreaks.com/forums/index.php?topic=226301.0

 

Is this the same problem I am having and if so, is there a way to define the character set easily to stop Firefox reloading?

 

Thanks

Link to comment
Share on other sites

I think that FF also does this when your default character encoding is different from the character encoding of the web page.

 

Since you have no control of what the browser is going to do or under what conditions it is going to do it, my post in the thread you linked to gives the best solution -

The best solution would be to set a session variable that says that the form processing code has executed once and then check this variable at the start of your code and skip the form processing for all the requests after the first one.

 

Is the code you posted just for showing that the page is being requested more than once or is it part of your application? It would take setting a session variable that contained a value specific to that page that is set at the end of the page (or at least after the point where you are setting/incrementing valid_fails) and then you test for this and don't increment valid_fails if you have already requested the current page.

Link to comment
Share on other sites

Hey.

 

Well I'm helping a friend out with an online game, this is one of the first tasks.

 

That page is a captcha test.  The valid_fails is the number of times they have left before they are banned.  But it decreases by 2 each time rather than one.

There is another session variable on that page which carries the correct number accross.  That is also getting screwed up somewhere so a lot of people are getting banned for no reason.

 

I think I'm going to have to rebuild it.  I hate trying to recode other peoples work.

Link to comment
Share on other sites

Does anybody have an example of the session variable?  I can't figure out a way to do it.

The problem is the links all page to the parent page but with different variables in the urls.  So the session is carried on and nothing is processed on the next page.  If I unset the session it pretty much defeats the object.

Link to comment
Share on other sites

<?php
// prevent double page requests from executing code
session_start();
$current = $_SERVER['SCRIPT_FILENAME']; // get the absolute path/filename of the current script
$_SESSION['last_requested_page'] = isset($_SESSION['last_requested_page']) ? $_SESSION['last_requested_page'] : ''; // set default if not already set

if($_SESSION['last_requested_page'] != $current){
// this page has not been visited immediately before the current request
// do any first time/one time processing here

// remember that you have visited this page
// this line of code can also be placed at the very end of the page (assuming that you don't have any exit/die statements before that point)
$_SESSION['last_requested_page'] = $current;
} else {
// any code that only gets executed after the first visit to the page
{
// any code that gets executed every time the page is requested
?>

Link to comment
Share on other sites

Well the problem is much bigger than what I thought.  Everything is affected by it, forum posts, captchas, game stats, pretty much everything is processed twice.

Is there not something I can simply put in the header to stop this happening?

 

How come I've never run into this problem before, is it only certain styles or something?

 

Thanks

Link to comment
Share on other sites

There are many reasons a web page will get requested twice -

 

FF - the character encoding problem.

 

IE - it seems to request pages twice while requesting the favicon file.

 

Some URL rewriting involving a missing trailing slash on the path (there may be other rewriting that causes two page requests...)

 

Javascript form submission and the browser's normal form submission.

 

If you are getting this on every page (have you tried it with different browsers?), it is likely that something on the server is causing it. You need to track down what is occurring. Is there any URL rewriting? Is this on an "add-on" domain that was added using URL rewriting instead of being added at the DNS level?

Link to comment
Share on other sites

You would need to post code to get any help with what it is doing that could be browser specific.

 

Are you redirecting using HTTP_REFERER, where it is set by one browser, resulting in going to the previous page, but it is not set in a different browser, resulting in redirecting to/refreshing the current page?

Link to comment
Share on other sites

Well I think I found the problem, it really can't be this simple can it??

 

<meta http-equiv="Content-Type" content="text/html charset=iso-8859-1" />

 

Changed to

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

 

Note the semicolon after text/html.

 

It seems to have done the trick, it can't be that simple, surely?

Link to comment
Share on other sites

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.