Session problem, please help me!!!
Posted: Fri Feb 06, 2004 3:17 am
Here is the simple user authentication I have made and try to verify the name and password from MySql database. The problem is that I cannot pass the session variable between pages, I mean to SUCCESS.PHP page.
All pages codes are given below, It has 3 pages,
1. LOGIN.PHP
2. AUTHENTICATE.PHP
3. SUCCESS.PHP
Here are the codes:
LOGIN.PHP
AUTHENTICATE.PHP
SUCCESS.PHP
Please let me know, What is the problem, I could not get the session variable at SUCCESS.PHP page.
All pages codes are given below, It has 3 pages,
1. LOGIN.PHP
2. AUTHENTICATE.PHP
3. SUCCESS.PHP
Here are the codes:
LOGIN.PHP
Code: Select all
<html>
<head>
<title>login Page</title>
</head>
<body>
<form method="POST" action="authenticate.php">
<p>Name:<input type="text" name="name" size="20"></p>
<p>Password:<input type="password" name="password" size="20"></p>
<p><input type="submit" value="Submit"><input type="reset" value="Reset"></p>
</form>
</body>
</html>Code: Select all
<?php
session_start();
$name = $HTTP_POST_VARSї'name'];
$password = $HTTP_POST_VARSї'password'];
$HTTP_SESSION_VARSї'name']=$name;
$HTTP_SESSION_VARSї'password']=$password;
//connect to the database...
mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);
//...and get number of result matched
$result = mysql_query("SELECT from login WHERE name='{$HTTP_POST_VARSї'name']}' AND password='{$HTTP_POST_VARSї'password']}'");
$rows=mysql_mun_rows($result)
if ($rows > 0)
{
//Redirect the user to success page to prompt him
session_register('$name');
require('success.php');
exit;
}
else
{
//unsuccessful login
echo 'sorry, you are not allowed, try again';
require('login.php');
exit;
}
?>SUCCESS.PHP
Code: Select all
<?php
session_start();
echo 'Welcome to Autherized Area';
echo 'you are logged as';
echo $HTTP_SESSION_VARSї'name'];
?>