Jump to content

SESSION error


brosjr

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.