PHP session variables not being maintaned

谁说我不能喝 提交于 2019-11-27 15:50:53
Linus Kleen

My suggestion from your previous question still stands: please compare session ids.

The solution might be as simple as your browser not accepting session cookies.

You retrieve the session id by calling session_id(). Do that right after session_start() it should give you a constant value if the session is the same. Otherwise for every request a new session is instantiated.

Also check C:\wamp\tmp. A gazillion files in this directory might indicate fresh sessions for each request.

EDIT Since we've confirmed new sessions per request, it's time to find out whether session cookies are accepted. Check the settings of your browser and confirm that a cookie for your domain (I guess it's "localhost") with the name PHPSESSID can be found.

Do you call session_start() on every page that accesses session data?

Edit: And do you receive the same session ID every time?
Also, could there be some error or warning you're missing (e.g. headers already sent) due to settings?

heximal

here is the sense in

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
{
  $_SESSION['saveddata'] = $row;
}

it rewrites $_SESSION['saveddata'] value on each iteration. may be you meant something like

 $_SESSION['saveddata'][] = $row;

it makes sense for $atid = $_SESSION['saveddata']['autotaskid'];

Review your session settings. You have a full list with:

<?php

phpinfo();

?>

Scroll down to the "Session" table.

Particularly, make sure that the session.save_path directory exists and is writeable.

When a new session ID is created with each request, most likely it is an issue with your session paths (save_path and cookie_path) and chances of this happening are greater if you're hosting different applications on one server (shared hosting) and some of these applications also implement sessions. This results in conflicts in your /tmp directory. You could change the config of your ini file, but it's best to configure these parameters during runtime.

session_set_cookie_params(0, "/app", ".domain.com");//set session cookie parameters
session_save_path("/home/../public_html/app/sess");//set directory of this app's session data
session_start();//start session

I hope that helps everyone having this issue. #CodeOn

I solved this problem on my local WAMP by clearing out the \tmp directory of old sessions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!