Jump to content

can i Assign normal variables the Value of my SESSIOn variable


rakyy

Recommended Posts

i have Created a Session  with this code $_SESSION['USER_NAME'] = trim($_POST['username'])

 

 

How can i access the $_SESSION['USER_NAME'] in other Pages ;

 

and will this code for $var = $_SESSION[uSER_NAME] 

 

can i get the SESSIOn value in " $var"  variable ??

How can i access the $_SESSION['USER_NAME'] in other Pages ;

 

Just like that.

 

and will this code for $var = $_SESSION[uSER_NAME] 

 

can i get the SESSIOn value in " $var"  variable ??

 

Yes, though make sure to use quotes between the square brackets otherwise you will get an error. $_SESSION['USER_NAME'] not $_SESSION[uSER_NAME]

 

Also, make sure you have session_start at the top of your script. In order to work with sessions, this function MUST have been called.

You need to have session_start() on both pages - the one where you set the session, and the one where you are trying to receive the session.

 

It's easy enough to test, just make these two files:

setsession.php

<?php

session_start();

$_SESSION['foo'] = 'bar';

 

getsession.php

<?php

session_start();

echo $_SESSION['foo'];

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.