A
Anonymous
Guest
I think you should add one more fields in MySQL i.e password; I think e-mail is not quite confidential; but e-mail will also do. Here is my code; I use username (Login name) and pass (Password)
To protect certain page, put this code above the <html> tag; i.e on top of your code
I hope this will help U, let me know if you're still having the problem.
This code is not secure enough to be used in online shopping..but it is enough for newbie...
Code:
<?php
//Start the output buffering
ob_start();
?>
<?php
start the session
session_start();
?>
<HTML>
<HEAD>
<title>My Website</title>
</head>
<body>
<?php
//declare the variables; host, username, password, dbase name
define ('HOST', 'localhost');
define ('USER', '');
define ('PASS', '');
define ('DB', 'researchers');
//If user hasn't logged in;
if (empty($HTTP_SESSION_VARS['username']))
{
//connect to the database...
mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);
//...and get number of result matched
$result = mysql_query("SELECT COUNT(*) AS numfound FROM maintable WHERE username='{$HTTP_POST_VARS['username']}' AND pass='{$HTTP_POST_VARS['pass']}'");
$result_ar = mysql_fetch_array($result);
//If no result is matched
if ($result_ar['numfound'] < 1)
{
//Redirect the user to error page to prompt him
header('Location: erlogin.htm');
exit;
}
//If user logged in successfully; register his/her username
$username = $HTTP_POST_VARS['username'];
session_register('username');
//Say a few words to welcome them
echo "<Center><font face=\"verdana\" color=\"#000000\" size=\"4\">Welcome to My Website</font></Center>";
}
?>
</body>
</html>
To protect certain page, put this code above the <html> tag; i.e on top of your code
Code:
<?php
ob_start();
session_start();
session_register('username');
?>
<?php
if (empty($HTTP_SESSION_VARS['username']))
{
header('Location: login.html');
exit;
}
?>
I hope this will help U, let me know if you're still having the problem.
This code is not secure enough to be used in online shopping..but it is enough for newbie...