brosjr Posted January 16, 2011 Share Posted January 16, 2011 hi all, I have a form that pass some $_POST values to a page that sets a session like this: session_start(); $_SESSION['TESTE'] = array ($_POST['sexo'],$_POST['nome'],$_POST['senha'],$_POST['senha2'],$_POST['login']); header ("Location: dddl.php"); Then the dddl.php should print the values on this line: print_r ($_SESSION['TESTE']) ; But when i run the application the dddl.php page returns this error: Notice: Undefined variable: _SESSION in C:\Users\Danilo\wamp\www\CNTur\dddl.php on line 2 Why it's not setting or why can't I reach the values? When I run the following code on the same page the session values are returned correctly: session_start(); $_SESSION['TESTE'] = array ($_POST['sexo'],$_POST['nome'],$_POST['senha'],$_POST['senha2'],$_POST['login']); print_r ($_SESSION['TESTE']) ; Thankx Danilo Jr. Link to comment https://forums.phpfreaks.com/topic/224568-session-error/ Share on other sites More sharing options...
kenrbnsn Posted January 16, 2011 Share Posted January 16, 2011 Do you have <?php session_start(); ?> in the second script? Ken Link to comment https://forums.phpfreaks.com/topic/224568-session-error/#findComment-1160027 Share on other sites More sharing options...
denno020 Posted January 16, 2011 Share Posted January 16, 2011 As kenrbnsn said above, you will need to add session_start() to every page that will want to access the session variables. It's a little confusing, I know I was when I first started using them, but by addying session_start(), all you're really saying is 'extend the current session into this file too'. It would be great if there was a session_extend() function or something similar, so that the names make it super easy to understand what's going on, but there isn't, so we have to stick with session_start(). I guess another way you could look at it is start the session acces for this file. So it's not starting a completely new sessions, it's merely starting the connection between the current session, and the file from where it is called.. Hope that helps. Denno Link to comment https://forums.phpfreaks.com/topic/224568-session-error/#findComment-1160036 Share on other sites More sharing options...
brosjr Posted January 16, 2011 Author Share Posted January 16, 2011 denno020, after add the session_start() on the dddl.php page the values were shown fine. Thank you Link to comment https://forums.phpfreaks.com/topic/224568-session-error/#findComment-1160077 Share on other sites More sharing options...
denno020 Posted January 16, 2011 Share Posted January 16, 2011 Wasn't just me buddy, kenrbnsn said that you needed it. I merely explained why . Denno Link to comment https://forums.phpfreaks.com/topic/224568-session-error/#findComment-1160079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.