Doyley Posted December 30, 2008 Share Posted December 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 30, 2008 Share Posted December 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
Doyley Posted December 30, 2008 Author Share Posted December 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
Doyley Posted December 30, 2008 Author Share Posted December 30, 2008 Wow, I can't even inset a row into the database without it being duplicated. :@ Quote Link to comment Share on other sites More sharing options...
Doyley Posted December 31, 2008 Author Share Posted December 31, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2008 Share Posted December 31, 2008 <?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 ?> Quote Link to comment Share on other sites More sharing options...
Doyley Posted December 31, 2008 Author Share Posted December 31, 2008 Thanks matey, I'll try that tomorrow when I sober up lol.. Happy new year!! Quote Link to comment Share on other sites More sharing options...
Doyley Posted January 1, 2009 Author Share Posted January 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 1, 2009 Share Posted January 1, 2009 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? Quote Link to comment Share on other sites More sharing options...
Doyley Posted January 1, 2009 Author Share Posted January 1, 2009 Yeah I've tried it with IE and firefox. The problem doesn't happen with IE. I've cloned the site and put it onto my dev server, the same problem happens. The is a global header used throughout the site, I'm guessing the problem must be in there. The site is http://www.ugcity.co.cc if you would be willing to take a look? Quote Link to comment Share on other sites More sharing options...
Doyley Posted January 1, 2009 Author Share Posted January 1, 2009 I created a page, a blank page that just inserts a row into a database. That works perfectly which leads me to believe that there is a coding error somewhere that just effects Firefox. hmmmmm Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 1, 2009 Share Posted January 1, 2009 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? Quote Link to comment Share on other sites More sharing options...
Doyley Posted January 1, 2009 Author Share Posted January 1, 2009 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? Quote Link to comment Share on other sites More sharing options...
Doyley Posted January 1, 2009 Author Share Posted January 1, 2009 Nope, it wasn't that simple. The problem has started again :@ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.