Session Variables being trashed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gestes
Forum Newbie
Posts: 5
Joined: Thu Dec 13, 2007 12:46 pm

Session Variables being trashed

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you sure the session isn't being lost somewhere between? (Showing the ID used will help you here.)
gestes
Forum Newbie
Posts: 5
Joined: Thu Dec 13, 2007 12:46 pm

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

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Not especially. We will probably need you to post your code.
gestes
Forum Newbie
Posts: 5
Joined: Thu Dec 13, 2007 12:46 pm

Here is some sample code...

Post 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]
Post Reply