Page 1 of 1

help with a global variable

Posted: Fri Nov 14, 2003 3:58 pm
by ericsodt
I am setting the global variable once I validate the user, however when I try and access that global variable it comes back as null...

LOGIN.PHP code snip

if( Decrypt(odbc_result($rs_results,"password")) == $password){
session_register('g_user_id');
$g_user_id = odbc_result($rs_results,"user_id");

MAIN.PHP
print $g_user_id [value is null]

Any thoughts???

Posted: Fri Nov 14, 2003 4:15 pm
by DuFF

Posted: Fri Nov 14, 2003 4:39 pm
by ericsodt
examples???

Posted: Fri Nov 14, 2003 4:51 pm
by ericsodt
I looked at that page and tried to do it how he said and I still can not set the session variable.. here is the code.

LOGIN:
if( Decrypt(odbc_result($rs_results,"password")) == $password){
$_SESSION['user_id'] = print odbc_result($rs_results,"user_id");
header("Location: tabs.php"); // GOING TO TABS.PHP
print $_SESSION['user_id']; //THIS WORKS AND PRINTS USER ID
die();

TABS.PHP
<? session_start() ?>

<?
print "session global =".$_SESSION['user_id']; // PRINTS OUT NULL
?>
Can anyone explain please...?????

Posted: Fri Nov 14, 2003 5:02 pm
by DuFF
Try this:

LOGIN:

Code: Select all

<?php
session_start();  //put this at the top of the page
if( Decrypt(odbc_result($rs_results,"password")) == $password){
$_SESSION['user_id'] = print odbc_result($rs_results,"user_id");
header("Location: tabs.php");
print $_SESSION['user_id'];
die();
}
?>
TABS.PHP

Code: Select all

<?php
session_start();
$userid = $_SESSION['user_id'];
echo "session global = $userid";
?>

Posted: Fri Nov 14, 2003 5:06 pm
by ericsodt
I have <? session start() ?> at the top already if you have AIM could you IM me and I could better describe my problem.. AIM: KICA5

Thanks for your help
DuFF wrote:Try this:

LOGIN:

Code: Select all

<?php
session_start();  //put this at the top of the page
if( Decrypt(odbc_result($rs_results,"password")) == $password){
$_SESSION['user_id'] = print odbc_result($rs_results,"user_id");
header("Location: tabs.php");
print $_SESSION['user_id'];
die();
}
?>
TABS.PHP

Code: Select all

<?php
session_start();
$userid = $_SESSION['user_id'];
echo "session global = $userid";
?>