Page 1 of 2
Session Problem
Posted: Mon Apr 05, 2004 9:59 am
by jrmontg
I am having a problem with sessions:
I am using Apache, PHP, APACHE on Windows XP pro.
I have a login page that creates a session. After loggin in a wanted to display the session.
Funny thing is that in Netscape it works fine but in IE6 I get this error:
Notice: Undefined index: Username in C:\Apache\Apache Group\Apache2\htdocs\userareas\home.php on line 120
HELP!?
Thanks
Jeff
Posted: Mon Apr 05, 2004 10:07 am
by magicrobotmonkey
What's the code? Is Username in the $_SESSION array or $_POST array? and are you sure its supposed to be capitalized?
Posted: Mon Apr 05, 2004 10:14 am
by jrmontg
Ok yes they were different. One was username and the other was Username. I changed it to lower case.
Getting the error: Notice: Undefined index: username in C:\Apache\Apache Group\Apache2\htdocs\userareas\home.php on line 120
This is from the login page:
} else {
mysql_free_result($rsLogin);
session_register("username");
$HTTP_SESSION_VARS['username'] = $HTTP_POST_VARS['username'];
header("Location: userareas/home.php");
}
On the next page I am displaying the session var with:
<?php echo $_SESSION['username']; ?>
Which is line 120.
Posted: Mon Apr 05, 2004 10:18 am
by magicrobotmonkey
try
$_SESSION['username'] = $_POST['username'];
instead of
$HTTP_SESSION_VARS['username'] = $HTTP_POST_VARS['username'];
I think those are no more and I think you can lose the
session_register("username");
Posted: Mon Apr 05, 2004 10:25 am
by tim
magicrobotmonkey wrote:try
$_SESSION['username'] = $_POST['username'];
instead of
$HTTP_SESSION_VARS['username'] = $HTTP_POST_VARS['username'];
I think those are no more and I think you can lose the
session_register("username");
exactly

Posted: Mon Apr 05, 2004 10:37 am
by jrmontg
I changed my login page:
mysql_free_result($rsLogin);
$_SESSION['username'] = $_POST['username'];
header("Location: userareas/home.php");
It still works in netscape but not IE6. Get error:
Notice: Undefined index: username in C:\Apache\Apache Group\Apache2\htdocs\userareas\home.php on line 117
Weird
Posted: Mon Apr 05, 2004 10:42 am
by tim
try loosing the header code.
JS works good and i've had problems with header outputs.
echo "<script language=javascript>location.replace('index.php')</script>";
Also - for giggles, you do have a session_start(); at the top of the page?
Posted: Mon Apr 05, 2004 10:49 am
by jrmontg
Yes, the session start is there.
Made the change:
$_SESSION['username'] = $_POST['username'];
echo "<script language=javascript>location.replace('userareas/home.php')</script>";
Still I get the same results.
Posted: Mon Apr 05, 2004 10:53 am
by magicrobotmonkey
You have session_start on both pages? And you get no errors on the first page - you're sure $_POST['username'] is set?
Posted: Mon Apr 05, 2004 10:55 am
by tim
then my guess would be you didnt set the variable username.
lets see that portion of code
Posted: Mon Apr 05, 2004 11:10 am
by jrmontg
There is a error on the login page. Sorry I didn't see it because I have a form on a different page and it just goes to the login page to validate. The error is:
Notice: Undefined variable: errorMessage in C:\Apache\Apache Group\Apache2\htdocs\login.php on line 55
Code:
<?php
session_start();
?>
<?php require_once('Connections/connUserareas.php'); ?>
<?php
$myUsername_rsLogin = "0";
if (isset($HTTP_POST_VARS['username'])) {
$myUsername_rsLogin = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['username'] : addslashes($HTTP_POST_VARS['username']);
}
$myPassword_rsLogin = "0";
if (isset($HTTP_POST_VARS['password'])) {
$myPassword_rsLogin = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['password'] : addslashes($HTTP_POST_VARS['password']);
}
mysql_select_db($database_connUserareas, $connUserareas);
$query_rsLogin = sprintf("SELECT Username, Password FROM companies WHERE Username = '%s' AND Password = '%s'", $myUsername_rsLogin,$myPassword_rsLogin);
$rsLogin = mysql_query($query_rsLogin, $connUserareas) or die(mysql_error());
$row_rsLogin = mysql_fetch_assoc($rsLogin);
$totalRows_rsLogin = mysql_num_rows($rsLogin);
if($HTTP_POST_VARS['action']=="login"){
if($totalRows_rsLogin==0){
$errorMessage = "Your Login Information is incorrect";
mysql_free_result($rsLogin);
} else {
mysql_free_result($rsLogin);
$_SESSION['username'] = $_POST['username'];
echo "<script language=javascript>location.replace('userareas/home.php')</script>";
}
}
error_reporting(E_ALL);
ini_set('display_errors', true);
?>
Posted: Mon Apr 05, 2004 11:19 am
by magicrobotmonkey
again, change $HTTP_POST_VARS to $_POST
the current error is from $errorMessage not being set because the outermost if statement it is in will never be true becasue $HTTP_POST_VARS['action'] is not set
also - you open and close php tages three times with nothing in between. Is that because you're cutting and pasting onto here?
Posted: Mon Apr 05, 2004 11:23 am
by jrmontg
Ok, done.
Posted: Mon Apr 05, 2004 11:24 am
by magicrobotmonkey
does it work?
Posted: Mon Apr 05, 2004 11:26 am
by jrmontg
Sorry,
No I still get a notice on the login page.
Notice: Undefined variable: errorMessage in C:\Apache\Apache Group\Apache2\htdocs\login.php on line 53
And still having the problem on the next page with IE.