Page 1 of 1

Losting values of _SESSION variable

Posted: Tue May 23, 2006 1:43 pm
by marthacecilia
hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I don't know why I lost the values of $_SESSION after use the PEAR Auth login.
I've a script called login.php for logging

Code: Select all

require_once 'DB.php';
require_once 'PEAR.php';
require_once 'Auth.php';
require_once 'HTML/QuickForm.php';

$auth_options = array(
'dsn' =>'sybase://sa:password@tcp+server8:5000/base',
'table' => 'website_auth',
'usernamecol' => 'login',
'passwordcol' => 'password');

$auth = new Auth('DB', $auth_options, 'login_function');

$auth->start();

print "<h1>User: ".$_SESSION['_authsession']['username']."</h1>\n";

$_SESSION['usuario_rol']='compras';


print "<a href=/licitaciones/pliegos.php>Pliegos de Compras</a>\n";

function login_function()
{
$form = new HTML_QuickForm('login', 'POST');
$form->addElement('text', 'username', 'User name:', 'size="10"');
$form->addRule('username', 'Please enter your user name!','required',null, 'client');
$form->addElement('password', 'password', 'Password:');
$form->addElement('submit', 'submit', 'Log In!');
$form->display();}

and in a pliegos.php:

Code: Select all

<? echo session_save_path();

if(session_id() == "")
{
echo 'No hay sesion abierta';
}
else
{
// Anything you want
}
echo $_SESSION['usuario_rol'];
I lost all the values I had post in the $_SESSION variable, when I'm using PHP 5. $_SESSION['usuario_rol'] is undefined.
Any help?
Thanks in advance.
Martha


hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 23, 2006 3:29 pm
by xpgeek
add

Code: Select all

session_start
function in the head of php script.

Posted: Tue May 23, 2006 3:31 pm
by J_Iceman05
you have to have "session_start()" at the top of the page in order to use the $_SESSION variables
example:

Code: Select all

// page 1
<?
session_start();
$_SESSION['var_name'] = 'value';
?>

// page 2
<?
session_start();
echo $_SESSION['var_name'];
?>
// (output = 'value')

// page 3
<?
echo $_SESSION['var_name'];
?>
// (output = '') because no "session_start();"