SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot rrreview's Avatar
    Join Date
    Jul 2002
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Login system won't work

    I keep getting this error on login.php when I post the data from index.php...
    Warning: Cannot add header information - headers already sent by (output started at /home/snt/public_html/whatever/run****.php:12) in /home/snt/public_html/whatever/login.php on line 15
    Here's the code for all the files...
    PHP Code:
    // THIS IS RUN****.PHP
    <?php 
    $User 
    "mylogin"
    $Pass "mypass"
    $Host "myhost"
    $DB "mydb"
    $Table "user"
    $database=mysql_connect($Host$User$Pass);
    mysql_select_db($DB);
    ?>
    PHP Code:
    // THIS IS INDEX.PHP
    <?php 
    if(!isset($_COOKIE['86QAV40NHT'])) {
    echo 
    "   <div align=\"right\">
       <table width=\"190\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#333333\">
       <tr><td>
       <form action=\"login.php\" method=\"POST\">
       <img src=""\"images/right_memberlogin.gif\" alt=\"\" vspace=\"8\"><br>
       <font class=\"whitetext\"><b>&nbsp;USERNAME</b><br>
       <input type=\"text\" name=\"Name\" size=\"15\" style=\"font-family: Verdana; font-size: 8pt\"><br>
       <font class=\"whitetext\"><b>&nbsp;PASSWORD</b><br>
       <input type=\"password\" name=\"Password\" size=\"15\" style=\"font-family: Verdana; font-size: 8pt\">&nbsp;&nbsp;<input type=\"submit\" name=\"submit\" value=\"LOGIN\" style=\"font-family: Verdana; font-size: 8pt; font-weight: bold\">
       </font></form>"
    ;
    } else {
    echo (
    "congratulations, you are logged in.");
    }
    ?>
    PHP Code:
    // THIS IS LOGIN.PHP
    <?php 
    include("run****.php"); 
    /*This is were the actual log in takes place.  We tell mysql to select the ID where the Name is exactly like the Name from the Form 
    where is Password is exactly like the encryption values of the password from the form.*/ 
    $sql "SELECT ID FROM " $Table " WHERE Name='" addslashes($_POST['Name']) . "' AND Password='" md5($_POST['Password']) . "' LIMIT 1"
    if(!(
    $result mysql_query($sql))) die(mysql_error()); 
    /*This is were we check the result.  We check to see how many rows were in the result of the query. If there is 1 one row in the result, that means 
    there is one username with the right information, so that would mean they are logged in.*/ 
    if(mysql_num_rows($result) == 1) { 
        
    /*Here we set a cookie that tells if the user has logged in and set it to last for a day.  The cookie is used on the members page to check 
        If they cookie is there they can see the page, if not they can't.*/ 
       
        
    setcookie("86QAV40NHT""TRUE"time()+(3600 24)); 

        
    /*You could also do the header() here just like I explained before.*/ 
        
    echo("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=http://mywebsite.com/whatever/index.php\">");
    } else { 
        echo 
    "Login failure"

    ?>
    It gives me that error, but it automatically goes to the index.php again, showing the login form. Why not use a header() you ask? It gave me another one of those "header already sent" error messages, so I thought I'd use a meta refresh tag to get rid of one of em.

    PLEASE help me. This is driving me insane.

  2. #2
    lean mean coding machine cosmo's Avatar
    Join Date
    Aug 2001
    Location
    the cosmos
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check your run***.php file. Ensure that there are no trailing spaces after the php tag closes.
    Luthfur R. - Web Developer
    PHP Lite.com - Professional PHP Scripts and Web Applications
    Calendar Express 2 - Web Based Calendar and Event Publishing System

  3. #3
    SitePoint Zealot rrreview's Avatar
    Join Date
    Jul 2002
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow. Something as small as that can mess up a script. Incredible. Thank you.

  4. #4
    lean mean coding machine cosmo's Avatar
    Join Date
    Aug 2001
    Location
    the cosmos
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're welcome
    Luthfur R. - Web Developer
    PHP Lite.com - Professional PHP Scripts and Web Applications
    Calendar Express 2 - Web Based Calendar and Event Publishing System


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •