Hello Everyone,
Thanks for taking your time to look at my post. I am having a problem with my PHP file which is giving me the following error whenever a header("Location: ") is used and the set_cookie function: Warning: Cannot modify header information and it always says the output was started on the first line, i'm really stuck becuase there is no whitespace either.
Here is my full file:
<?php
$user = $_COOKIE['userloggedin'];
$error = $_GET['error'];
$login = $_POST['login'];
if(isset($login)) {
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
if($username == "" and $password == "") {
header("Location: ?error=both");
}elseif($username == "") {
header("Location: ?error=username");
}elseif($password == "") {
header("Location: ?error=password");
}else{
include("includes/database.php");
$select = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'");
$check = mysql_num_rows($select);
if($check == "0") {
header("Location: ?error=incorrect");
}else{
$fetch = mysql_fetch_array($select);
$username_new = $fetch['username'];
setcookie("userloggedin", $username_new);
header("Location: account.php");
exit;
}
}
}
if($user != "") {
header("Location: account.php");
exit;
}
$title = "Login";
require("templates/header.php");
?>
<DIV class="inner_content guest_home_page">
<DIV>
<br />
<br />
<H2>Login</H2></DIV>
<br />
<DIV class="clear"></DIV>
<DIV class="welcome-signup" style="width: 100%">
<DIV class="home_page_intro">
<?php
if(isset($error)) {
?>
<div class="login_alert">
<?php
if($error == "both") {
echo "You did not type your username or password, please try again.";
}elseif($error == "username") {
echo "You did not type your password, please try again.";
}elseif($error == "password") {
echo "You did not type your password, please try again.";
}elseif($error == "incorrect") {
echo "The details you entered are incorrect, please try again.";
}
?>
</div>
<? }else{ ?>
<P>Login to this site using the form below:</P>
<? } ?>
</DIV>
<DIV class="guest_login_bar" style="width: 100%">
<IMG alt=MEMBERS src="images/members_login_header.gif">
<DIV class=leading_line><A
href="forgot.php">Click here</A> if you
have forgotten your password. </DIV>
<FORM method="post" action="login.php">
<UL>
<LI><LABEL for="username">Username</LABEL> <INPUT id="username" class="text" type="text" name="username"></LI>
<LI><LABEL for="password">Password</LABEL> <INPUT id="password" class="text" type="password" name="password">
<INPUT class="submit imgover" alt="Go" src="images/submit.gif" name="login" type="image" value="Go"></LI>
</UL>
<SPAN class=leading_line>Not a member? <A href="register.php">Click here</A> to join. </SPAN>
</FORM>
</DIV>
</DIV>
</DIV>
<?php require("templates/footer.php"); ?>
Thanks in advance!