Jump to content

[SOLVED] $_SESSION Variable


rgraham45

Recommended Posts

I have tried to understand and read tutorials about accessing the session variables and I can't figure this out.

 

Here is the code

session_start();

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');

header('Cache-Control: post-check=0, pre-check=0', FALSE);

header('Pragma: no-cache');

 

$user_id = $_SESSION['is_admin'];

print "<p>session var: ";print $user_id;print "<p>session var: <p>";

print_r($_SESSION);

 

 

here is the result:

 

session var:

 

session var:

 

Array ( [sESSION] => Array ( [user_id] => 8 [customer_id] => [is_admin] => 1 [first_name] => John [last_name] => Poppe [allow_customize] => 0 ) [enrollment_customer_id] => 9 [enrollment_user_id] => 116 )

 

$_SESSION['is_admin'] contains a value of 1 when I display the $_SESSION array, but when I try to get the value from the session variable I get nothing

 

I am missing something here, any ideas, thanks

Link to comment
https://forums.phpfreaks.com/topic/51997-solved-_session-variable/
Share on other sites

<?php

session_start();

if (!isset($user_id)){
$_SESSION['is_admin']='rgraham45'; // you gotta actually declare something
$user_id = $_SESSION['is_admin'];
}
else
{
$user_id = 'somePreviouslySetValue';
}

print ("The current value of the session variable is {$_SESSION['is_admin']}<br />");
print ("See for yourself:<br />");
print_r($_SESSION['is_admin']);

?>

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.