PDA

View Full Version : "Undefined index" error in Login application


DanielTech
07-31-2004, 04:05 PM
I am getting "Undefined index" error every time I use $_SESSSION['password'] in a Login application. It looks like my $_SESSSION['password'] is not defined or something similar. Any idea?
Here is my code:

//Login.php

<?php
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<FORM METHOD="POST" ACTION="members.php">
Enter your Name: <input type="text" name="name">
<br>Enter password: <input type="password" name="password"><br>
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>

//members.php

<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<html>
<head>
<title>Members</title>
</head>
<body>
<?

echo "<strong>Members page</strong><br />";

// Get the user's input from the form
$name = $_POST['name'];



// Register session key with the value
$_SESSION['name'] = $name;
$_SESSSION['password'] = $_POST['password'];

// Display the sssion information:
?>

Welcome to my website <strong><? echo $_SESSION['name']; ?></strong>!<br/>
<?
if($_SESSION['password']=='')
{
echo 'yes';
}
else
{
echo 'no';
}
?>
Your pass is: <? echo $_SESSION['password']; ?><br><br>
Let's see what happens on the <a href='logout.php'>next page.</a><br/><br/>
</body>
</html>

thanks,
DanielTech

bcarl314
07-31-2004, 04:57 PM
Probably running an older version of PHP. I've created some login scripts for clients on local boxes running PHP 4.3, then upload to the server where they're running 4.0 or something earlier.

Try doing a global search / replace of "$_SESSION" with $HTTP_SESSION_VARS.