help with a global variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

help with a global variable

Post 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???
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

Post by ericsodt »

examples???
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

Post 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...?????
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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";
?>
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

Post 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";
?>
Post Reply