0

How reliable is a method of setting variables into a session and then retrieving them on another page?

I have a script where users drag and drop elements on a page utilizing jQuery UI. I record transactions using AJAX, however, sometimes I get results missing project ID, or to be exact I get 0. I set this ID into a session variable when users first get on this script page. The page has an included JS file with my functions and from there the transaction data is sent to an AJAX page where I store transactions into my db. Because the project ID is the same I get it from my session. It is not a consistent error, happens only once in a while, but it bothers me a lot.

Why is it happening randomly? And how can I fool-proof my code?


UPDATE: OK, it seems it's something else that may be interfearing with that particular session ID.

I do have session_start(); on every page where I use sessions and I set them the same way I set all my sessions: `$_SESSION['project'] = $projectID;

Back to debugging...

santa
  • 12,234
  • 49
  • 155
  • 255
  • Your question is way to vague. You have a very specific issue, but not providing any code or try to isolate the issue. $_SESSION is reliable, but maybe not the way you're using it. – Evert Jan 24 '12 at 14:54
  • 3
    A comment on its reliability. http://stackoverflow.com/questions/676846/do-ajax-requests-retain-php-session-info – Josh Jan 24 '12 at 14:56

1 Answers1

3

Yes, you can rely on PHP sessions. If you are getting odd results, it seems like your going to have to debug your code until you find the issue.

472084
  • 17,666
  • 10
  • 63
  • 81
  • 4
    Further, 90% of common session problems on SO are a lack of `session_start()` on all of the pages that need access to sessions. – Charles Jan 24 '12 at 15:02