Ok I got this new problem while hosting my php files in a server which never happened while i worked in wamp. its a simple user registration & login form. Registration part is alright, but I cannot login properly, whenever I login it shows up the following error along with the welcome message:
[I]
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/foodecrp/public_html/beta3/login.php:5) in /home/foodecrp/public_html/beta3/login.php on line 7
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/foodecrp/public_html/beta3/login.php:5) in /home/foodecrp/public_html/beta3/login.php on line 7[/I]
Welcome! Click here to enter the MEMBER’S page
When I click “Click here”, the members page says “You need to be logged in”, this error never came up in WAMP! Please help!
Code for Login.php
<?php
session_start();
$username = $_POST['username'];<-----Line 7
$password = $_POST['password'];
if ($username&&$password)
{
include "config.php";
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
//Check to See if they match
if ($username==$dbusername&&md5($password)==$dbpassword)
{
echo "Welcome! <a href='member.php'>Click here</a> to enter the MEMBER'S page";
$_SESSION['username']=$username;
}
else
echo "Incorrect Password!";
}
else
die("That user doesn't exist!");
}
else
echo("Please enter and username and a password!");
?>
Code for Member.php
<?php
if ($_SESSION['username'])
echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Log out</a><br><a href='changepassword.php'>Change password</a>";
else
die("You must be logged in!");
?>