Page 1 of 1
More Help on Sessions Needed
Posted: Thu Jul 11, 2002 11:49 pm
by saadatshah
PHP Version 4.0.6 on Linux and Apache
****** file1.php
//// starting session
session_start();
//// registering session variables
session_register("UserName,UserID,SessionID,SessionTime");
$_SESSION['UserName'] = $txtLogin;
$_SESSION['UserID'] = 1;
$_SESSION['SessionID']= session_id();
$_SESSION['SessionTime']= time();
//// printing session variables
print($_SESSION['UserName']);
print($_SESSION['UserID']);
print($_SESSION['SessionID']);
print($_SESSION['SessionTime']);
end of file1.php*************************************
********file2.php
//// starting session
session_start();
//// printing session variables
print($_SESSION['UserName']);
print($_SESSION['UserID']);
print($_SESSION['SessionID']);
print($_SESSION['SessionTime']);
****end of file2.php
Note:-----
The first file register and prints the session variables but ...the second file doesn't .....can anyone help me...point out what is the mistake in my code......v r running PHP 4.0.6 on a LINUX sever with APACHE Web server.......... and register_global is on....so i need ur quick help...
Posted: Fri Jul 12, 2002 12:34 am
by gnu2php
It worked fine for me (I think). I'm using PHP 4.2.1. The problem must be that you're using 4.0.6.
According to the PHP documentation, if I understand correctly, the $_SESSION variable is not a global variable until 4.1.0--
Note: As of
PHP 4.1.0, $_SESSION is available as global variable just like $_POST, $_GET, $_REQUEST and so on. Not like $HTTP_SESSION_VARS, $_SESSION is always global. Therefore, global should not be used for $_SESSION.
http://www.php.net/manual/en/ref.session.php
I'm not sure how to get around this problem--since I've never used session functions--so you may want to read
Session handling functions in the PHP docs.
Posted: Fri Jul 12, 2002 2:00 am
by twigletmac
As gnu2php pointed out, $_SESSION only works in PHP 4.1 and above so not in 4.0.6. For that you'll need $HTTP_SESSION_VARS and
session_register.
Why don't you have a look at the
tutorial on sessions at phpcomplete.com.
Mac
Posted: Fri Jul 12, 2002 6:27 am
by saadatshah
hi,
i ve replaced the $_SESSION with $HTTP_SESSION_VARS in my code...but this iz still not workin......the article u suggested ...i ve already read that and the documentation 2.....but cant fix my problem.....any more sugesstions?????
Posted: Fri Jul 12, 2002 7:26 am
by twigletmac
Apologies, but having just reread the documentation for
session_register() I noticed the following caution:
php manual wrote:If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister().
I would therefore amend your code by removing the session_register() statement and convert all $_SESSION references to $HTTP_SESSION_VARS. Otherwise use session_register() in place of $HTTP_SESSION_VARS, it appears to be that you should choose one or the other and not use both.
Mac
Posted: Fri Jul 12, 2002 10:47 pm
by saadatshah
************ file1.php
<?
//// starting session
session_start();
$HTTP_SESSION_VARS['UserName'] ="Test";
$HTTP_SESSION_VARS['UserID'] = 1;
$HTTP_SESSION_VARS['SessionID']= session_id();
$HTTP_SESSION_VARS['SessionTime']= time();
//// printing session variables
print($HTTP_SESSION_VARS['UserName']);
print($HTTP_SESSION_VARS['UserID']);
print($HTTP_SESSION_VARS['SessionID']);
print($HTTP_SESSION_VARS['SessionTime']);
/* when session_register() is used
//// registering session variables
//session_register("UserName,UserID,SessionID,SessionTime");
//// printing session variables
print("<br>" . $UserName);
print("<br>" . $UserID);
print("<br>" . $SessionID);
print("<br>" . $SessionTime);
*/
?>
******************
********** file2.php
<?
//// starting session
session_start();
//// printing session variables
print($HTTP_SESSION_VARS['UserName']);
print($HTTP_SESSION_VARS['UserID']);
print($HTTP_SESSION_VARS['SessionID']);
print($HTTP_SESSION_VARS['SessionTime']);
/* when session_register() is used
print("<br>" . $UserName);
print("<br>" . $UserID);
print("<br>" . $SessionID);
print("<br>" . $SessionTime);
*/
?>
**********************************
hello guy.....this is my new code but this is also not workin....now what??????????
Posted: Mon Jul 15, 2002 1:39 am
by twigletmac
You are still using session_register() and $HTTP_SESSION_VARS together. Try using just one or the other.
Mac
Posted: Wed Jul 17, 2002 1:49 am
by saadatshah
hi,
i think u didnt take a close look at the code...the sessio_register(); portion is commented in my code....