sinse the last time I posted, I went away and learnt something 🙂
im creating a user system for my new site http://www.allegianceofsound.uk.tt and have got everything working BUT I am trying to implement sessions so im not just having the one page you can login to saying hello (and the username)- here are the errors its returning:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/www/miclau4.freecoolsite.com/testing/login.php:1) in /home/www/miclau4.freecoolsite.com/testing/login.php on line 31
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/miclau4.freecoolsite.com/testing/login.php:1) in /home/www/miclau4.freecoolsite.com/testing/login.php on line 31
and here's my code:
<?php $username= $_POST['username'];
$password= $_POST['password'];
if( (!$username) || (!$password) )
{
echo("<center><h1>Enter your username and password</h1></center>");
}
$conn = mysql_connect( "host", "user", "password");
$rs = @mysql_select_db("db",$conn) or die("Could not select database");
$sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$rs = mysql_query( $sql, $conn ) or die("Could Not Execute Query");
$num = mysql_numrows( $rs );
if( $num!=0 )
{
session_start();
$_SESSION['loggedin'] = "1";
$msg = "Welcome <b>$username</b>";
}
else
{
$msg = "Login Failed, please try again";
}
?>
<html>
<head>
<title><?php echo($msg); ?></title>
</head>
<body>
<?php echo($msg); ?>
</body>
</html>