开发者

Session Variables Not Sticking

开发者 https://www.devze.com 2023-03-16 03:41 出处:网络
I\'m sorry guys -- after two hours of looking and commenting out and so on, I found one tiny include that was referencing a redirected domain. Somehow this threw everything else off. I\'m still not su

I'm sorry guys -- after two hours of looking and commenting out and so on, I found one tiny include that was referencing a redirected domain. Somehow this threw everything else off. I'm still not sure why, but by fixing that file to the new domain I was able to fix it. Again, thanks for your help and time in replying to me!

I'm fairly familiar with sessions in PHP, yet I can't tell why these session variables are not sticking on this login system I have. When I log in, I get successfully sent to the index page, but any pages therein I get kicked back to the login page, and also when I reload the index page. I开发者_Go百科 have echoed the session variable $_SESSION['login'] on the index page to make sure its value has accurately been carried over, and it's is there..

... code removed


My wild guess but usually a problem I always encounter in Apache under Linux when dealing with sessions.

Check session.save_path in php.ini. If there's a path there and doesn't exist in your system, create it e.g. session.save_path = "/var/lib/php/session". I'm guessing PHP cannot create session files and thus session won't persist across pages. Give the folder a write permission too, try 0777 (but it's not the best permission as it allows all users). HTH!


Why are you destroying the session during login? This is probably a reason.

session_start();
session_unregister('login');
session_write_close();
session_start();
session_destroy();

You probably might just call session_start() and clear 'login' session value:

<?
$ERRBG="";
$ERRMSG="";
session_start();
$_SESSION['login'] = null;
require_once("db/mysql_connect.php");
.......


Use session_start() only once in the php page at the starting

Do not use session_destroy(). If you want to remove session variable, use unset function. In case if you want to remove all the variables use session_unset function

Use session_destroy() as the logout operation


Please do this step :

  1. use session_start() at the top of page after <?php just once .
  2. don't destroy session
  3. write var_dump($_SESSION) on in your test-index and write it in that page when you click on it , it's redirect to login page ( insert die() after it ) !

I think session start in your test-index but not in your other page

report result to me !

0

精彩评论

暂无评论...
验证码 换一张
取 消