Jump to content

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'];

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.