Jump to content

setcookie error


fery0098

Recommended Posts

hello

 

i use the fallowing code for my login page but it gives me the fallowing error i was wondering what is the problem? (line 179 is the setcookie)

by the way it doesn't set the cookie

any help would be appreciated :)

error:

Warning: Cannot modify header information - headers already sent by (output started at /home2/sportsh9/public_html/test/login_acc.php:6) in /home2/sportsh9/public_html/test/login_acc.php on line 179

 

my code:

                        <?
                        include_once('functions.php');
                        


function cleanQuery($string)
{
  if(get_magic_quotes_gpc())  // prevents duplicate backslashes
  {
    $string = stripslashes($string);
  }
  $badWords = "(delete)|(update)|(union)|(insert)|(drop)|(http)|(--)";
  $string = eregi_replace($badWords, "", $string);
  if (phpversion() >= '4.3.0')
  {
    $string = mysql_real_escape_string($string);
  }
  else
  {
    $string = mysql_escape_string($string);
  }
  return $string;
}

if (isset($_COOKIE['scmuser'])) {
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">";
}else{
if ($_POST['username']) {
//did they supply a password and username
$username=cleanQuery($_POST['username']);
$password=cleanQuery($_POST['password']);
if ($password==NULL || $username==NULL) {
?>

<p align="center">
      <font color="#FF0000">Username or password wasn't supplied!</font><form action="login_acc.php" method="POST">
        <table style="border:1px solid #FFFFFF;" width="90%" align="center">
          <tr>
            <td align="center">Username:  </td>
            <td align="center">
            <input type="text" size="20" maxlength="25" name="username" /></td>
          </tr>
          <tr>
            <td align="center">Password:  </td>
            <td align="center">
            <input type="password" size="20" maxlength="25" name="password" /></td>
          </tr>
          <tr>
            <td align="center" colspan="2">
            <input type="submit" value="Login"/> </td>
          </tr>
          <tr>
            <td align="center" colspan="2">
            <a href="register.php">Register</a> - <a href="forgetpass.php">Forgot Your Password?</a>
            </td>
          </tr>
        </table>
      </form>

<?
}else{

$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
?>


<p align="center">
      <font color="#FF0000">The supplied login was incorrect</font><form action="login_acc.php" method="POST">
        <table style="border:1px solid #FFFFFF;" width="90%" align="center">
          <tr>
            <td align="center">Username:  </td>
            <td align="center">
            <input type="text" size="20" maxlength="25" name="username" /></td>
          </tr>
          <tr>
            <td align="center">Password:  </td>
            <td align="center">
            <input type="password" size="20" maxlength="25" name="password" /></td>
          </tr>
          <tr>
            <td align="center" colspan="2">
            <input type="submit" value="Login"/> </td>
          </tr>
          <tr>
            <td align="center" colspan="2">
            <a href="register.php">Register</a> - <a href="forgetpass.php">Forgot Your Password?</a>
            </td>
          </tr>
        </table>
      </form>


<?
}else{


$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
setcookie("scmuser", "$username", time()+3600);
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">";
}
}
}
}
?>

 

thank you :)

Link to comment
Share on other sites

The answer to your question was staring you in the face before you posted this. The very first stikied and locked post at the top of the PHP forum is titled "HEADER ERRORS - READ HERE BEFORE POSTING THEM". The answer you are looking for is there:

 

http://www.phpfreaks.com/forums/php-coding-help/header-errors-read-here-before-posting-them/

Link to comment
Share on other sites

Given that the opening php tag is not in the left-most column, I'm going to guess you have 5 lines of HTML tags at the start of the file, that you did not post, plus the white-space we see before the opening php tag. All of that is output that cannot occur before any setcookie/header/session_start... statement.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.