Switching to "$_SESSION" from "session_regis
Posted: Sun Mar 11, 2007 5:24 am
Hi
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.
The following is the code at the top of the news page that the members are redirected to when the preceding script completes correctly.
What's happening is that when the user reaches the news page with the session_start etc on it, they're being redirected to the index page as if the session isn't being stored.
I'm not sure which bit I've messed up!
Any help gratefully accepted.
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.