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?
Do you put session_start(); at the top of each page ? Try putting print_r( $_SESSION ); at the top of each page so that you can track down which page your variables are getting trashed. Brew
Yeah Brewster has probably got the right answer there! If you don't use session_start() at the top of each script you wont be able to access the session variables.
Sunnyverma, 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: <?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> PHP:
i think it is not a coding problem. But it is due to server configration edit session.gc_maxlifetime in php.ini increase time. I hope it will work
yea, i was thinking that the session is being reset either by timeout or a problem on the server. It has happened to me before. Look at the php.net reference for sessions... you should find some valuable info that can solve your problem. sessions dont live forever, unless you set them to and even then are not consistent because they are always going to be temporary.