Web Hosting Talk







View Full Version : Session variables get messed


arzhan
08-13-2006, 03:02 PM
I'd been breaking my head on the below issue:

I have a search page that will display 5 results per page.User can navigate using Next and Previous buttons in the search results page. Iam using PHP,MySQL,Apache combo

My Logic:
======
1)When user clicks on search, i get the criertia using $_POST
2)I save the criertia in the session to be used by NEXT and PREVIOUS
I start the session using session_start();
3)When user clicks on NEXT, i call the same PHP file passing some values (like whether user clicked on next/previous,what is the currect page etc)

This code works perfectly fine in my localhost, but doesnt after i hosted the site

Problem:
======
When the user clicks on NEXT, i see the message 'no results' found though there are 15+ results.I tried to print the values of the session variables everytime the PHP file is called and here is what i found out...
1)When the file is executed for the first time,search criteria successfully stored in session.I could retrieve and print them also
2)On clicking Next, the file is called for the second time.But the values of the session variables are different now.It is holding the values of the last record displayed in the first page
And hence the query fails showing me zero records

I dont quite understand as why the session variables are not retained.

Localhost (my m/c)
======
PHP - 4.4.0
Apache - 2.0.54 (WIN32)

Hosting server
=============================
PHP - 4.4.3
Apache - 1.3.37 (Unix)

Have made only one change to my file after i launched. Localhost in the URL replaced by my site name...

Localhost:
<td><A HREF="http://localhost/srch.php?id=2&currentpage=<?php echo $currentpage; ?>"><img src="Next.PNG"/></A></td>

Site:
<td><A HREF="http://www.XYZ.com/srch.php?id=2&currentpage=<?php echo $currentpage; ?>"><img src="Next.PNG"/></A></td>


Any help to resolve this issue will be much appreciated.If you need more information, please let me know.

ahk2chan
08-13-2006, 03:39 PM
2)On clicking Next, the file is called for the second time.But the values of the session variables are different now. It is holding the values of the last record displayed in the first page.


could you please explain a bit more about the bold sentence?

If it works locally but not in your hosting environment, it seems to me that it is an issue about the hosting env setup.

There are a few parameters that you want to check in php.ini
session.save_path
session.save_handler
session.use_trans_sid

Also you can check with phpinfo() and make sure that your php is not compiled with --disable-session

Hope this helps.