There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP SESSION flakyness


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
cpscdave's Avatar
Senior Member with 279 posts.
 
Join Date: Feb 2004
Experience: Intermediate
24-Sep-2007, 06:48 PM #1
PHP SESSION flakyness
I've been working on a bill_payment area for a stie we maintain. and a really weird thing just happened.

I was working on some code that in no way shape or form touched sessions, and all of the sudden the system wouldnt save any session information.

I checked the usual problems, the disk wasnt full, the system could write to the save dir.
rebooted my computer, tried a different computer

Banged my head for almost an hour.

Finally commented out a section of code which (I was goign to delete anyways cause its not needed) doest touch sessions in any way shape or form but is BEFORE session_start and is different from the section of code I was working on when this happened. and all of the sudden its started to work again...

really wierd....

anyone have any other ideas of what might have been going on???

I'd love to try and figure out what caused it before we launch this into production
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook

Spam a problem for you? http://spamooze.com
cpscdave's Avatar
Senior Member with 279 posts.
 
Join Date: Feb 2004
Experience: Intermediate
24-Sep-2007, 07:13 PM #2
grrr its happened again :@ dont know whats going on. Any suggestions would be loved
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,208 posts.
 
Join Date: Oct 2006
25-Sep-2007, 09:25 AM #3
Quote:
Originally Posted by http://php.net/session_start
Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.
cpscdave's Avatar
Senior Member with 279 posts.
 
Join Date: Feb 2004
Experience: Intermediate
25-Sep-2007, 09:40 AM #4
Yep have that in there.

The relevant code is: (guess I should've posted this yesterday)
PHP Code:
session_start();

if(!isset(
$_SESSION['generated']))
 {
   
$_SESSION['generated'] = time();
   
$stage 1;
   echo 
"new session";
 }
else
 {
   if(
time() - $_SESSION['generated'] < $MAX_TIME)
   {
     
$_SESSION['generated'] = time();  //refresh the value;
     
echo "session refreshed";

   }
   else
   {
     
/*
      * more time than allowed has passed, destory the session will force them
      * to restart from the start
      */
     //explicitlly dump everything in the session array
     
foreach(array_keys($_SESSION) AS $key)
     {
       
$_SESSION[$key]='3242rerfdasklf';
       unset(
$_SESSION[$key]);
     }
     
session_destroy();
     echo 
"I'm sorry too much time has elapsed. Please refresh to restart";
     
$restart true;

   }
 } 
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,208 posts.
 
Join Date: Oct 2006
25-Sep-2007, 12:33 PM #5
I thought you said you have code 'BEFORE' session_start()?
cpscdave's Avatar
Senior Member with 279 posts.
 
Join Date: Feb 2004
Experience: Intermediate
25-Sep-2007, 01:26 PM #6
Ya just setting a couple flags like MAX_TIME

I think I may have found the culprit. We link into the framework that we use and in there a couple ini settings were being change specifically it looks as if it was forcing php to use cookies for the sessions.

I think it was getting confused jumping back and forth between client side and server side session tracking.

Since making that change I havent been able to get the problem to happen again... but cause it's inconsitant I'm not 100% sure.
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook

Spam a problem for you? http://spamooze.com
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,208 posts.
 
Join Date: Oct 2006
25-Sep-2007, 02:17 PM #7
Quote:
Originally Posted by cpscdave
Ya just setting a couple flags like MAX_TIME

I think I may have found the culprit. We link into the framework that we use and in there a couple ini settings were being change specifically it looks as if it was forcing php to use cookies for the sessions.

I think it was getting confused jumping back and forth between client side and server side session tracking.

Since making that change I havent been able to get the problem to happen again... but cause it's inconsitant I'm not 100% sure.
The default is for PHP to use cookies for sessions: http://www.php.net/session
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:14 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.