Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.