RE: [PHP] Dissapearing Session Variables (long post)
| From: | Warren Vail | Date: | Thu, 06 Sep 2001 04:52:27 +0000 |
| Subject: | RE: [PHP] Dissapearing Session Variables (long post) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66149@lists.php.net to get a copy of this message | ||
Jason,
I had a similar problem using a php session table in MySQL to store session
data, turns out my data item was too small to contain all my registered
session variables, I changed the definition of the data column to TEXT and
that seemed to do it. I also found that I needed to run addslashes() before
updating the column and stripslashes() retrieving it (turns out some of my
variables contained characters that MySQL was sensitive to, and others that
caused serialize/unserialize problems).
Not sure this is your problem, but it's worth checking.
Warren Vail
-----Original Message-----
From: Jason Bell [mailto:jbell@barkingrat.com]
Sent: Wednesday, September 05, 2001 4:54 PM
To: PHP Users
Subject: [PHP] Dissapearing Session Variables (long post)
Hello! I'm trying to figure out why my session variables keep hiding....
Background:
On my site, I have a login box, which allows you to login. This login box
works as expected. It authenticates the provided credentials against my
database, and then sets some pre-registered session variables to values
pulled from the DB. What I am experiencing, is that my session variables
will be defined, and then lose their values when the first link is followed.
I've placed a reference to $PHPSESSID into the title of the page, and note
that the $PHPSESSID remains constant. Is there something in my code that is
causing this? Is there a way that I can rewrite my code to help avoid this?
Here is my index.php, other relevent code to follow:
<?
include("include/user.conf");
if (!$theme) { $theme = "default"; };
include("include/core_functions.php");
if ($AuthAction) {
switch($AuthAction) {
case login:
include("include/db.conf");
$sql = "SELECT uid,username,password,first,last,acl FROM users
WHERE username='$username' AND password=PASSWORD('$password')";
$result = mysql_query($sql) or die ('Unable to execute SQL
Query.');
$dberror=mysql_error();
$dbnum=mysql_errno();
if ($dberror) {
$AuthErr = $dberror;
} else {
$num = mysql_numrows($result);
if ($num !=0) {
$sess_uid = mysql_result($result,0,"uid");
$sess_acl = mysql_result($result,0,"acl");
$sess_fname = mysql_result($result,0,"first");
$sess_lname = mysql_result($result,0,"last");
$sess_uname = mysql_result($result,0,"username");
$sess_auth = "1";
} else
$AuthErr = "<FONT SIZE=-1 COLOR=RED>Login Incorrect!</FONT>";
};
};
break;
case logout:
break;
}
};
if (!$action) { $action = tba; };
if (!$title) { $title = "$PHPSESSID"; };
if (!$headline) { $headline = "<H2>An E-Haven for Displaced
Northpointers<H2>"; };
include("Themes/".$theme."/".$theme.".theme");
?>
Here is user.conf:
<?php
if (!$PHPSESSID) {
$sess_uid = "";
$sess_acl = "";
$sess_fname = "";
$sess_lname = "";
$sess_uname = "";
$sess_auth = "";
session_register('sess_uid');
session_register('sess_acl');
session_register('sess_fname');
session_register('sess_lname');
session_register('sess_uname');
session_register('sess_auth');
};
?>
Shouldn't this work? I reference the session variables within functions,
but that shouldn't effect anything. I always make sure to call global for
each variable before I use it.... any ideas?
Thanks in advance!
Jason Bell