Page 1 of 1

Problems with sessions...

Posted: Mon Dec 23, 2002 7:36 am
by Elmseeker
I am working on a user authentication system and so far I have the following:

Code: Select all

<?
if ($submital == "submit") {
$connection = mysql_connect("$host","$sqluser","$pass");
if ($connection == false) {
        echo mysql_errno . ": " . mysql_error() . "<br>";
        exit;
}
mysql_select_db('kidstop');
$query = "SELECT * FROM staff WHERE u_name = '$name'";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)) {    
if ($name == $row["u_name"]) {
if (md5($pass1) == $row["u_pass"]) {
$login = mysql_fetch_array($result);   
session_register("login");
echo "<BR>You are now logged in as ".$row["u_name"]." with a user level of ".$row["u_level"]."!\r\n";
} else { // pass
echo "<BR>Unable to login at this time!<BR> Bad Password!";
}
} else {
echo "<BR>Unable to login at this time!<BR> Bad Name!"; // name
}
} else {
echo "<BR>Unable to login at this time!<BR> No Result!"; // result
}
} else {
echo "<BR>Unable to login at this time!<BR> Nothing submitted!"; // submitted
}
?>
And in a second file I have:

Code: Select all

<?
if ( $login ) {
echo "Found Login Session!!!!!<BR>";
} else {
echo "Can not find login session as \$login!!!!!<BR>";
}
if ( session_is_registered('login'))
echo "Welcome back ".$u_name."!<BR>";
else
echo "Session not registered!<BR>";
?>
The output I am expecting to get when someone is logged in (me for example) is:
Found Login Session!!!!!
Welcome Back Elmseeker!
Instead what I am getting is:

Code: Select all

Can not find login session as $login!!!!!
Welcome back !
I also can not access any of the variables that should be stored in the array. I have tried using $HTTP_SESSION_VARS["login"] = $login; and tried calling them back using $HTTP_SESSION_VARS as well, but that didn't seem to work either...

PHP Version is 4.0.1pl2, globals are on...*hangs his head*
Thanks for any help you may provide.

Posted: Mon Dec 23, 2002 11:19 am
by nieve
try putting this at the top of the file
session_start();

Problems with sessions...

Posted: Mon Dec 23, 2002 1:15 pm
by Elmseeker
Oh, forgot to mention that, it's there already. I just upgraded the PHP to 4.2.3 and I am still having the same problem. I can post the whole php.ini file here if I need to...

Also, I just tried to echo the $_SESSION like so:

Code: Select all

print_r($_SESSION);
And it output:

Code: Select all

Array ( &#1111;login] =&gt; )
It seems that login does exist but it's not populated even though it SHOULD be populated:

Code: Select all

$login = mysql_fetch_array($result);
Really not sure what the problem could be and why it isn't populating the array with information from the row...

Thanks again...

Hmm...

Posted: Mon Dec 23, 2002 1:38 pm
by Elmseeker
Well...don't ask me how because I don't have a darn clue, but all of a sudden the array is populated full the brim with everything it's supposed to have in it, I still have one small problem though...

The array looks like this:

Code: Select all

Array ( &#1111;login] => Array ( &#1111;0] => 1 &#1111;ID] => 1 &#1111;1] => Elmseeker &#1111;u_name] => Elmseeker &#1111;2] => Eric T. Benoit &#1111;r_name] => Eric T. Benoit &#1111;3] => b6c17ede134cc05fd2db432b5e9deb45 &#1111;u_pass] => b6c17ede134cc05fd2db432b5e9deb45 &#1111;4] => tiffani@farviolet.com &#1111;email] => tiffani@farviolet.com &#1111;5] => 10 &#1111;u_level] => 10 ) )
Is there now a way without having to define every element of the array on every page to be able to use like $u_name for example? or do I have to either use $_SESSION["login"]["u_name] or $u_name = $_SESSION["login"]["u_name] everytime I want to reference something? This is only one of the arrays I need to access this way on the site I'm working on and some of them are MUCH bigger, to have to define them all over and over again would simply be a pain in mt buttox...thanks again!

Posted: Tue Dec 24, 2002 3:25 am
by evilcoder
My moto, if its not broke dont fix it! If thats working dont go any further, just be content that its all good. :)