www.webdeveloper.com
Results 1 to 3 of 3

Thread: Login Errors

  1. #1
    Join Date
    May 2012
    Posts
    5

    Login Errors

    I seem to get the following error on this page...

    Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 110

    Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 111

    Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 112

    Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 113

    Here's my code. What am I doing wrong?
    The lines it refers to are where the login success post script is, specifically the 4 lines with "setcookie"

    PHP Code:
    <?php
    error_reporting 
    (E_ALL E_NOTICE);
    session_start();
    ?>

    <html>

    <title></title>

    <head>

    <style type="text/css">

    body{
    color:white;
    background-color:black;
    }

    #backdiv
    {
    width: 100%;
    height: 100%;
    min-width: 800px;
    min-height: 800px;
    background-color: black;
    position: relative;
    }
    #frontdiv
    {
    width: 650px;
    height: 400px;
    background-color: gray;
    position: absolute;
    left: 500px;
    top: 200px;
    }
    #logindiv
    {
    width: 350px;
    height: 120px;
    background-color: black;
    position: absolute;
    top: 200px;
    left: 1250px;
    }
    #footerdiv
    {
    width: 900px;
    height: 100px;
    background-color: black;
    position: absolute;
    top: 700px;
    left: 375px;
    }

    </style>

    </head>

    <body>

    <?php

        
    if ($_POST['loginbtn']){
            require(
    'connect.php');
            
    $username mysql_real_escape_string($_POST['user']);
            
    $username strip_tags($_POST['user']);
            
    $pass mysql_real_escape_string($_POST['pass']);
            
    $pass strip_tags($_POST['pass']);
            
    mysql_close();
            
            if (
    $username){
                if (
    $pass){
                    require(
    'connect.php');
                    
                    
    $password md5(md5("salt".$pass."salt"));
                    
                    
    $query mysql_query("SELECT * FROM tc_members WHERE username='$username'");
                    
    $numrows mysql_num_rows($query);
                    
    mysql_close();
                    if (
    $numrows == 1){
                        require(
    'connect.php');
                        
    $query mysql_query("SELECT * FROM tc_members WHERE username='$username'");
                        
    $row mysql_fetch_assoc($query);
                        
    $dbid $row['id'];
                        
    $dbuser $row['username'];
                        
    $dbpass $row['password'];
                        
    $dbactive $row['emailactivated'];
                        
    $dbadminuser $row['admin_user'];
                        
    $dbadminentity $row['admin_entity'];
                        
    $dbadminart $row['admin_art'];
                        
    $dbadmingalaxy $row['admin_galaxy'];
                        
    $dbadminglobal $row['admin_global'];
                        
    $dbsubscription $row['subscription'];
                        
    $dbcharacter $row['character'];
                        
    mysql_close();
                                            
                        if (
    $password == $dbpass){
                            if (
    $dbactive == 1){
                                
    // set session info
                                
    $_SESSION['username'] = $dbuser;
                                
    $_SESSION['id'] = $dbid;
                                
    $_SESSION['character'] = $dbcharacter;
                                
    $_SESSION['subscription'] = $dbsubscription;
                                (
    $dbadminuser == 1)? $_SESSION['admin_user'] = $dbadminuser null ;
                                (
    $dbadminentity == 1)? $_SESSION['admin_entity'] = $dbadminentity null ;
                                (
    $dbadminart == 1)?$_SESSION['admin_art'] = $dbadminart null ;
                                (
    $dbadmingalaxy == 1)?$_SESSION['admin_galaxy'] = $dbadmingalaxy null ;
                                (
    $dbadminglobal == 1)?$_SESSION['admin_global'] = $dbadminglobal null ;
                                
    setcookie("username"$dbuser0);
                                
    setcookie("id"$dbid0);
                                
    setcookie("subscription"$dbsubscription0);
                                
    setcookie("character"$dbcharacter0);
                                
    $login_ip $_SERVER['REMOTE_ADDR'];
                                
    $login_date date("M d, Y");
                                
    $login_year date("Y");
                                
    $login_day date("z");
                                require(
    'connect.php');
                                
    mysql_query("UPDATE tc_members SET last_logindate = '$login_date', last_loginday='$login_day', last_loginyear='$login_year', last_loginip = '$login_ip' WHERE username = '$dbuser'");                            
                                                            
    $success =  "<font color='white'>Welcome <b>$dbuser</b></font>";
                                                            
    $enter "<center>$success<br><hr><br><form action='members.php' method='post'><input type='submit' value='Click to Enter'></form></center>";
                                                            
                                                            
    $query_num mysql_query("SELECT * FROM tc_ip_log WHERE username='$dbuser' AND ip_address='$login_ip'");
                                
    $numrows mysql_num_rows($query_num);
                                if(!
    mysql_num_rows($query_num) || mysql_num_rows($query_num) < 1){
                                    require(
    'connect.php');
                                    
    mysql_query("INSERT INTO tc_ip_log VALUES ('', '$dbuser', '$login_ip', '$login_date', '$login_year', '$login_day', '')");
                                    
    $inquery mysql_num_rows(mysql_query("SELECT * FROM tc_ip_log017 WHERE ip_address='login_ip'"));
                                    
    mysql_close();
                                    if(
    $inquery 1){
                                        require(
    'connect.php');
                                        
    mysql_query("UPDATE tc_ip_log SET login_date='$login_date' WHERE username='$dbuser' ip_address='login_ip'");
                                        
    mysql_query("UPDATE tc_ip_log SET multi_flag='Yes' WHERE ip_address='login_ip'");
                                        
    mysql_close();
                                    }else ;
                                }elseif(
    mysql_num_rows($query_num) > 0){
                                    require(
    'connect.php');
                                    
    mysql_query("UPDATE tc_ip_log SET login_date='$login_date', log_year='$login_year', log_day='$login_day' WHERE username='$dbuser' AND ip_address='$login_ip'");
                                    
    $query_1 mysql_query("SELECT * FROM tc_ip_log017 WHERE ip_address='$login_ip'");
                                    
    $numrows_1 mysql_num_rows($query_1);
                                    
    mysql_close();
                                    if(
    $numrows_1 1){
                                        require(
    'connect.php');
                                        
    mysql_query("UPDATE tc_ip_log SET login_date='$login_date' WHERE username='$dbuser' ip_address='login_ip'");
                                        
    mysql_query("UPDATE tc_ip_log SET multi_flag='Yes' WHERE ip_address='$login_ip'");
                                        
    mysql_close();
                                    }else ;
                                }else    ;                    
                            }
                            else 
                                
    $alert =  "<font color='red'>You must activate your account to login.</font>";
                        }
                        else 
                                            
    $alert "<font color='red'>Incorrect password.</font>";
                    }
                    else 
                                    
    $alert "<font color='red'>Incorrect username.</font>";
                }
                else 
                            
    $alert "<font color='red'>You must enter a password to login.</font>";
            }
            else 
                    
    $alert "<font color='red'>You must enter a username to login.</font>";
        }
        else 
            ;
    ?>

    <?php

    echo "
    <div id='backdiv'>
    <div id='frontdiv'><center><font color='white'>insert 650 x 400 pic here with clickable map function</font></center></div>
    <div id='logindiv'>
        <table border='0' cellspacing='2' cellpadding='1'>
            <tr>
                <form action='index.php' method='post'>
                    <td colspan='4' bgcolor='gray'><center>User Login</center></td>
            <tr>
            <td><font color='white'>Username:</font></td>
            <td colspan='2'><input type='text' name='user' tabindex='1'></td>
            <td width='150'><a href='index_forgotusername.php' tabindex='5'>Lost Username</a></td>
        </tr>
        <tr>
            <td><font color='white'>Password:</font></td>
            <td colspan='2'><input type='password' name='pass' tabindex='2'></td>
            <td width='150'><a href='index_forgotpassword.php' tabindex='6'>Lost Password</a></td>
        </tr>
        <tr>
            <td></td>
            <td><input type='submit' name='loginbtn' value='Login' tabindex='3'></form></td>
                    <form action='index_register.php' method='post'>
                    <td><input type='submit' value='Register' tabindex='4'></form></td>
        </tr>
            <tr>
                    <td colspan='4'><font color='red'><center> 
    $alert </center></font></td>
            </tr>
            <tr>
            </tr>    
        </table><br> 
    $enter
        </div>
    <div id='footerdiv'><font color='white' size='2'><center>blah</center></font></div>
    </div>"
    ;

    ?>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2011
    Posts
    1,156
    You need to move your PHP code above the <html> tag (and you should use a <!DOCTYPE> as well, for browser compatibility issues), because once you've sent output to the user, the server response headers will have been sent and you can't modify them for things like cookies and the server response codes.

  3. #3
    Join Date
    May 2012
    Posts
    59
    If you wish to get around this... and you do not wish to do what rtrethewey suggested...

    Set output buffering to on (in php.ini) and you can use header() when ever you like in a script it also will speed up your PHP scripts as the internal writes go to a buffer instead of being outputed to the browser every X bytes. In fact... Output buffering was the difference between a PHP script on my computer running in 0.3 seconds compaired to 0.05 seconds or something rediculous like that anyway

    Kind regards,
    Scott

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles