NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
session not working before redirect


Joined: 09 Jun 2006
Posts: 6
Location: atlanta, ga
Reply with quote
i am trying to set a session variable directly before a meta refresh

<meta http-equiv="Refresh" content="0;url=<?=$page?>">

why is my session variable not being stored. It works fine running in a browser
View user's profileFind all posts by lewisvSend private message


Joined: 10 Feb 2004
Posts: 93
Reply with quote
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?
View user's profileFind all posts by gilzowSend private messageAIM Address


Joined: 09 Jun 2006
Posts: 6
Location: atlanta, ga
Reply with quote
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.
View user's profileFind all posts by lewisvSend private message


Joined: 10 Feb 2004
Posts: 93
Reply with quote
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?
View user's profileFind all posts by gilzowSend private messageAIM Address


Joined: 09 Jun 2006
Posts: 6
Location: atlanta, ga
Reply with quote
It works fine in explorer, i am having problems with the debugger.
View user's profileFind all posts by lewisvSend private message


Joined: 10 Feb 2004
Posts: 93
Reply with quote
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.
View user's profileFind all posts by gilzowSend private messageAIM Address


Joined: 09 Jun 2006
Posts: 6
Location: atlanta, ga
Reply with quote
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.
View user's profileFind all posts by lewisvSend private message


Joined: 10 Feb 2004
Posts: 93
Reply with quote
lewisv wrote:
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
Code:
session_start()
before you do anything with your sessions, and before you output anything to the browser (ie print, echo, etc.). You dont have to worry about stopping the session, since session data is stored automatically when your script is terminated. If you need to stop the session for some reason before your script is finished, you can use
Code:
session_write_close()

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.
View user's profileFind all posts by gilzowSend private messageAIM Address
Site Admin

Joined: 13 Jul 2003
Posts: 8340
Reply with quote
Quote:
when i have auto_start = 1 and run it in the debugger, it does not work.

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
View user's profileFind all posts by dmitriSend private messageVisit poster's website
session not working before redirect
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic