Page 1 of 1

Session Handling Help Required

Posted: Sat Jul 06, 2002 12:11 am
by saadatshah
///// Starting Session

session_start();

////// Registering Session Variables

$UserName="somethong";
$UserID="1";
$SessionID=session_id();
$SessionTime=time();

session_register("UserID");
session_register("UserName");
session_register("SessionID");
session_register("SessionTime");

///// printing variables

print($_SESSION['UserName']);
print($_SESSION['UserID']);
print($_SESSION['SessionID']);
print($_SESSION['SessionTime']);


******* **********

when this page is accessed first time...it gives the following notices....when i refresh th page it print the values of the session variables.....

****************

Notice: Undefined index: UserName in D:\test\admin.php on line 42

Notice: Undefined index: UserID in D:\test\admin.php on line 43

Notice: Undefined index: SessionID in D:\test\admin.php on line 44

Notice: Undefined index: SessionTime in D:\test\admin.php on line 45

Re: Session Handling Help Required

Posted: Sat Jul 06, 2002 1:16 am
by protokol

Code: Select all

session_start();

   // Registering Session Variables

   $_SESSIONї'UserName'] = "somethong";
   $_SESSIONї'UserID'] = "1";
   $_SESSIONї'SessionID'] = session_id();
   $_SESSIONї'SessionTime'] = time();
   
   // printing variables	
			
   print($_SESSIONї'UserName']);
   print($_SESSIONї'UserID']);
   print($_SESSIONї'SessionID']);
   print($_SESSIONї'SessionTime']);
Basically, session_register() is not used anymore in the newer versions of PHP. Instead you can just access the $_SESSION array directly as I did above, by setting values to each of the variables.

Posted: Sat Jul 06, 2002 2:00 am
by saadatshah
thx .....
which version of php u were talking abt.....in ur eply

Posted: Sat Jul 06, 2002 5:15 am
by twigletmac
Version 4.1 and up can use $_SESSION. If you had an older version you still need to use session_register() - AFAIK - and can access the variables using the $HTTP_SESSION_VARS array.

Mac

Posted: Sat Jul 06, 2002 8:31 am
by LenHewitt
sadaatshah,

The problem with your dode is that you are registering the session variables after declaring them:

session_start();

////// Registering Session Variables

session_register("UserID, UserName, SessionID, SessionTime");


$UserName="somethong";
$UserID="1";
$SessionID=session_id();
$SessionTime=time();

will work