session not working before redirect |
|
It would definitely help if you could show us a bit more of your code on how you are doing things. First, did you start the session before you tried setting the session variable?
|
||||||||||||
|
|
here is two simple pages that show the error
-------------------------------------------------------- redir1.php <?php function redirect($page) { ?> <meta http-equiv="Refresh" content="0;url=<?=$page?>"> <?php exit; } ?> <?php $_SESSION['page_temp'] = 'hello'; redirect('redir2.php'); ?> redir2.php <?php // $_SESSION['page_temp'] = 'hello'; echo 'before echo - '; if(array_key_exists('page_temp', $_SESSION)) { echo $_SESSION['page_temp']; echo ' - '; session_unregister('page_temp'); } else echo 'not found - '; echo 'before echo'; ?> I have autostart enabled in the php ini. I tried to manually start and stop the sessions but had some issues. Don't remember what that was it has been months. |
||||||||||||
|
|
not sure... i copied your code exactly (but had to add session_start at the beginning of each file since I do not have autostart enabled) and it worked perfectly. redir1.php set the meta-refresh, sent me to redir2.php where it printed out before echo - hello - before echo
I would say the problem lies in your php configuration. where is php.ini saving your session files? maybe it cant store them? Also, have you tried running your scripts in debug mode? |
||||||||||||
|
|
It works fine in explorer, i am having problems with the debugger.
|
||||||||||||
|
|
just tried it in the debugger after i posted that and it works fine there. I'm able to walk through the whole thing and if i set a watchpoint on the session, am able to see hello inserted, and then later unregistered.
|
||||||||||||
|
|
ok, it is auto_start
when i have auto_start = 1 and run it in the debugger, it does not work. when i have auto_start = - and run it it works. So here is my next questions. If this a bug in the debugger? or do i have something set up wrong? Php question: How do i convert my pages to use session_start. Do i need to just put session_start at the top of each page? When do i call session stop? Sorry i am still learning php. |
||||||||||||
|
|
At the most basic, you just have to put
since you are new to sessions, I would strongly recommend reading the PHP Chapter on Sessions, and make sure to read the pdf on Session Fixation. Personally, I use a wrapper function to handle all the various session settings (name, save path, expiration, use only cookies, secure, etc). You can also write your own session handlers so that you can store your session data to a database instead of using the servers file storage. |
||||||||||||||||||
|
Site Admin
|
I could not replicate any problems with sessions when ran your scripts in the debugger. Everything went good. Please check if you have set auto_start On for the php that you run with debugger. Just run phpinfo() with debugger to check. |
||||||||||||||
_________________ The PHP IDE team |
session not working before redirect |
|
||
Content © NuSphere Corp., PHP IDE team
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by