Rohan72
11-01-2007, 06:45 AM
I have a members area on my website. And have both the script to create a name and password, and to login to the members area. To my own surprise I managed them both to work.
My problem now is that anyone still can access that members area, as long as they know the name of that page. How can i make that page secure so that if they give in the url of the page, they can not get in.
The only way to enter that page would be by login in.
Is it also possible to log the users out as soon as they close the protect page?
Here is the login script (I hope this is enough information):
<?php
ob_start();
$host="localhost"; // Host name
$username="***"; // Mysql username
$password="***"; // Mysql password
$db_name="***"; // Database name
$tbl_name="leden"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$lid=$_POST['lid'];
$pasw=$_POST['pasw'];
// encrypt password
$pasw_md5=md5($pasw);
$sql="SELECT * FROM $tbl_name WHERE lid='$lid' and pasw_md5='$pasw_md5'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
echo "Beste ", $lid, ", we verbinden u nu door...";
session_register("lid");
session_register("pasw");
header("location:memb1.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
My problem now is that anyone still can access that members area, as long as they know the name of that page. How can i make that page secure so that if they give in the url of the page, they can not get in.
The only way to enter that page would be by login in.
Is it also possible to log the users out as soon as they close the protect page?
Here is the login script (I hope this is enough information):
<?php
ob_start();
$host="localhost"; // Host name
$username="***"; // Mysql username
$password="***"; // Mysql password
$db_name="***"; // Database name
$tbl_name="leden"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$lid=$_POST['lid'];
$pasw=$_POST['pasw'];
// encrypt password
$pasw_md5=md5($pasw);
$sql="SELECT * FROM $tbl_name WHERE lid='$lid' and pasw_md5='$pasw_md5'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
echo "Beste ", $lid, ", we verbinden u nu door...";
session_register("lid");
session_register("pasw");
header("location:memb1.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>