Page 1 of 1

Session Variables being trashed

Posted: Thu Dec 13, 2007 12:55 pm
by gestes
In my app, the user selects a state from a map. Selecting that state takes you to the first PHP page with the request var of "state" being passed in. I set the $_SESSION['state'] = "georgia" (for instance), then every page from that point forward, uses the state as part of the SQL query to focus info to just that state.

The issue I have is this. You can visit the first page, and all the counties in the given state show up as selectable. If you select the form again, it works fine, but at a point (typically3 or 4 times) the $_SESSION['state'] returns an empty value causing the SQL statement to be invalid.

What is happening to my session value? I have searched the code and no-where am I invalidating that session variable other than when the user exits the site. I have put echo(...) comments to help, but nothing is showing up.

Can anyone help me here?

Posted: Thu Dec 13, 2007 1:08 pm
by feyd
Are you sure the session isn't being lost somewhere between? (Showing the ID used will help you here.)

It happens w/ not "other" code...

Posted: Mon Dec 17, 2007 3:17 pm
by gestes
I can show the form with a listing of counties, then select a link to the same page from the menu, and on the 3rd or 4th time, the $_SESSION value will be empty.

There are no other pages or code that is passed through.

Does this help clarify my confusion?

Posted: Mon Dec 17, 2007 3:39 pm
by feyd
Not especially. We will probably need you to post your code.

Here is some sample code...

Posted: Tue Dec 18, 2007 10:34 am
by gestes
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have simplified the code, removed any included and mainlined them into the example and am still getting the same results. Initially, when the page comes up, you get the county name, but after you refresh a few times (not consistent), it eventually will be an empty array(). Also, the $_SESSION value is not coming up at all in IE, but works as explained in Firefox.

Here is the simplified code:

Code: Select all

<?php session_start(); ?>

<html>
<head>
  <title>Test Database</title>
  <link rel="stylesheet" href="../styles/style.css" type="text/css">
</head>

<body bgcolor="#F2F4C4">
  <h1><center>Sample Database</center></h1>
  <font face="Arial">
  <center>
    <hr width="80%"/>

    <br>
    <a href="./advanced_search.php">Search by County</a>

<?
    print_r($_SESSION);     //If you refresh the browser page, this will eventually return array().
?>

    <hr width="80%"/>
    <h5>Developed by <a href="http://www.bgesoftware.com" target="_blank">BGE Software, Inc.</a></h5>
  </center>
  
  </font>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]