Click to See Complete Forum and Search --> : php login script problem


DREW
07-09-2007, 06:38 AM
Can anyone tell me what i'm doing wrong once my login gets to the loggedin.php page and it checks to see if the session is created it sends back to the login page thinking that the session isn't created but it is

login form

<?php
$host = ".........";
$dbname = ".......";
$username = "........";
$password = "........";

$connection = mysql_connect($host, $username, $password);
mysql_select_db($dbname,$connection);

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM members 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 to file "login_success.php"
//script to check user name and password would be coded here

//if authentication is successfull
session_start();
$_SESSION['loggedin'] == 1;

echo "<script type=\"text/javascript\">
location.href=\"loggedin.php\";
</script>";
}
?>

logged in page (which this script gets to)

<?php
if ($_SESSION['loggedin'] != 1)

{
echo "<script type=\"text/javascript\">
location.href=\"index.php?section=about\";
</script>";
}
else{
echo"logged in";
}




any help appreciated

Cheers,
Drew

hschmitz
07-09-2007, 06:49 AM
You have to call session_start() before you can use the $_SESSION variable.
So on both pages, just put the session_start() command on the first line of your PHP code and everything should work fine