Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I think its a cookie problem....

iceklowniceklown Member Posts: 9
[code]<?php
$username = $_POST[username];
$password = $_POST['password'];
$query = "SELECT rank FROM login";
$mysql_access = mysql_connect("localhost",'mike-ne' ,'jjeor' );
mysql_select_db("mikene_crossstatic");
$result = mysql_query($query, $mysql_access);


while($myrow = mysql_fetch_array($result))
{
$rank = $myrow['rank'];
$user = $myrow['username'];
$pass = $myrow['password'];
$userid = $myrow['id'];
if($user == $username && $pass==$password)
{
$cookiealogin = $username . $password;
setcookie('username', $cookiealogin, time()+3600);
setcookie('userid', $userid, time()+3600);
}
if($rank == 'Admin')
{
setcookie('rank', $rank, time()+3600);
}
}
?>
[/code]
My friend is writing a script and this is the code he gave for a login script.
The error he gets is..
[b]
Warning: Cannot add header information - headers already sent by (output started at /home/mike-ne/public_html/cross-static/login.php:2) in /home/mike-ne/public_html/cross-static/login.php on line 25[/b]
Please reply if you notice anything wrong.

Comments

  • Mark StrijbosMark Strijbos Member Posts: 82
    : The error he gets is..
    : [b]
    : Warning: Cannot add header information - headers already sent by (output started at /home/mike-ne/public_html/cross-static/login.php:2) in /home/mike-ne/public_html/cross-static/login.php on line 25[/b]

    well, what is unclear about this?
    IMHO the error says it all: you already wrote some output to the browser. Cookies have to be sent prior to _anything_ else (including whitespace, carriage returns etc). check your login.php code and make sure NOTHING gets sent before the cookies (they have to be part of the header info)

  • jeskejeske Member Posts: 23
    : : The error he gets is..
    : : [b]
    : : Warning: Cannot add header information - headers already sent by (output started at /home/mike-ne/public_html/cross-static/login.php:2) in /home/mike-ne/public_html/cross-static/login.php on line 25[/b]
    :
    : well, what is unclear about this?
    : IMHO the error says it all: you already wrote some output to the browser. Cookies have to be sent prior to _anything_ else (including whitespace, carriage returns etc). check your login.php code and make sure NOTHING gets sent before the cookies (they have to be part of the header info)
    :
    :
    I agree with Mark on the error message. Somewhere, prior to this section of code, PHP is sending something back to the browser. Also, a couple of other comments. First, you may want to edit your original message and remove your username and password from the $mysql_access statement, just so that it isn't publicly posted. Secondly, it doesn't appear that you will ever find an 'admin' in the rank table, because you don't have a WHERE clause.
    SELECT rank from login
    WHERE user = 'username'
    AND pass = 'password'

    Hope this helps.

    Jeff
  • Shawn CarterShawn Carter Member Posts: 0

    _______ // http://forcoder.org // free ebooks and video tutorials about { Visual Basic R JavaScript Visual Basic .NET PL/SQL MATLAB Assembly Swift Python Ruby Java Scratch PHP Objective-C Go C C++ Delphi Perl C# Awk F# Fortran Rust Scala ABAP D VBScript Lisp Crystal Hack Apex Clojure Prolog FoxPro Transact-SQL Erlang Bash Alice Dart Kotlin Lua Logo Julia SAS LabVIEW Scheme COBOL Ada ML } __________

Sign In or Register to comment.