Warning: Cannot modify header information

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronolivar
    New Member
    • Feb 2010
    • 2

    Warning: Cannot modify header information

    I looked all over the web, and i just cant find the answer.. how can i do this? I want that when the user inputs an invalid username or password my page would automatically redirect to the log.in page..

    a snippet of the problem area..

    Code:
    if(!($dbh=@mysql_connect($host,$username,$password)))
       { header('Location:index.html');
         //print "<a href=http://localhost/pms/index.html>Back to login.</a><br>";
         //print "access denied.";
       }
    the warning is at
    (output started at C:\xampp\htdocs \PMS\login.php: 2) in C:\xampp\htdocs \PMS\login.php on line 13
    line 13 is the if statement.. i tried suppressing the warning, but it still wont work!.. :( any ideas??
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    Give us more code as this error is issued when headers are already sent. You can not have any output before redirection. Even white space before opening tag will result in this error.

    Comment

    • ronolivar
      New Member
      • Feb 2010
      • 2

      #3
      Code:
      <?php
      
      $username=$_POST["UsernameBox"];
      $password=$_POST["PasswordBox"];
      $host="localhost";
      
      
         //error_reporting(0);  
      
      
      if(!($dbh=@mysql_connect($host,$username,$password)))
         { header('Location:index.html');
           //print "<a href=http://localhost/pms/index.html>Back to login.</a><br>";
           //print "access denied.";
         }       
      else  
         { print "sample login....";    
           mysql_close($dbh);
          
         }  
         
      
      
      ?>
      this is just about it..

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        Ok

        mysql_connect opens connection to a MySQL Server and user should not have anything to do with it. Big NO NO NO. Security Alarm :)))

        There is loads of tutorials on how to make Login Script using php. I only searched for a second and found this:



        I must say I didn't try it but it looks ok.

        Good Luck

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by ronolivar
          I looked all over the web, and i just cant find the answer..
          Really? This is one of the more common problems people face when starting out with PHP. There are literally hundreds of threads on this topic here at Bytes.

          But anyways. You should start by readin through this article draft by Markus. It deals specifically with this problem.

          If you can't locate it, post the first ~20 lines of your login.php script and we will take a look and see if we can spot it.

          Comment

          Working...