I implemented a fairly simple login script to protect a members-only area of a site. It all worked fine. Then, after reading several posts here I realised that the method I used - session_register was now deprecated in favour of $_SESSION. So I've attempted to change the script to fit unfortunately something's not right.
The following is the processing page which is sent the info by the form.
Code: Select all
// 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 signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$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
$_SESSION['myusername'] = $username;
$_SESSION['mypassword'] = $password;
header("location:members/news.html");
}
else {
header("location:/userlogin1.html");
}
?>Code: Select all
<?
session_start();
if (!isset($_POST['username']) && !isset($_POST['password']))
header("location: /index.html");
?>I'm not sure which bit I've messed up!
Any help gratefully accepted.