error message on session_register

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    error message on session_register

    hi ive been using a login code which uses sql & db its quite simple and has been working great.....but as i have just gone to do a final test on the site i've built starting from the login page i get the following error message...

    "Warning: session_registe r() [function.sessio n-register]: Cannot send session cache limiter - headers already sent (output started at /home/theau10/public_html/resources/checklogin.php: 1) in /home/theau10/public_html/resources/checklogin.php on line 30

    Warning: Cannot modify header information - headers already sent by (output started at /home/theau10/public_html/resources/checklogin.php: 1) in /home/theau10/public_html/resources/checklogin.php on line 32"

    I don't know why it is doing this as it has been working great before.

    here is the login code

    Code:
    <title>: : : members online resource centre</title><?php
    $username="theau10_tawUser";
    $password="auction10";
    $database="theau10_resources";
    
    // Connect to server and select databse.
    $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
    
    mysql_select_db("$database") or die("Unable to select database!");
    
    // username and password sent from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];
    
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:tsandcs.php");
    }
    else {
    header("location:incorrect.php");
    }
    ?>
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #2
    ive tried again and this message came up

    Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_global s is enabled. You can disable this functionality and this warning by setting session.bug_com pat_42 or session.bug_com pat_warn to off, respectively. in Unknown on line 0

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      ok ive read up session_registe r is deprecated and that the use of $_SESSION is prefered.

      ive changed my code to the following but i still get a error message of "Warning: Cannot modify header information - headers already sent by (output started at /home/theau10/public_html/resources/checklogin.php: 1) in /home/theau10/public_html/resources/checklogin.php on line 32"

      session_registe r("myusername") ;
      session_registe r("mypassword") ;

      my new code is

      Code:
      <title>: : : members online resource centre</title><?php
      $username="theau10_tawUser";
      $password="auction10";
      $database="theau10_resources";
      
      // Connect to server and select databse.
      $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
      
      mysql_select_db("$database") or die("Unable to select database!");
      
      // username and password sent from form
      $myusername=$_POST['myusername'];
      $mypassword=$_POST['mypassword'];
      
      // To protect MySQL injection (more detail about MySQL injection)
      $myusername = stripslashes($myusername);
      $mypassword = stripslashes($mypassword);
      $myusername = mysql_real_escape_string($myusername);
      $mypassword = mysql_real_escape_string($mypassword);
      
      $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
      $result=mysql_query($sql);
      
      // Mysql_num_row is counting table row
      $count=mysql_num_rows($result);
      // If result matched $myusername and $mypassword, table row must be 1 row
      
      if($count==1){
      // Register $myusername, $mypassword and redirect to file "login_success.php"
      $_SESSION["myusername"] = "$myusername";
      $_SESSION["mypassword"] = "$mypassword";
      header("location:tsandcs.php");
      }
      else {
      header("location:incorrect.php");
      }
      ?>

      Comment

      • hoopy
        New Member
        • Feb 2009
        • 88

        #4
        Its due to this:

        <title>: : : members online resource centre</title>

        You cannot send any output to the browser before you use a header() call.

        Just remove it and it should work fine.

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          ok ill try that.....thank you...

          since session_is_regi stered has deprecated as well i will have to work on a different way to check if a session is registered..... has anyone got any suggestions to point me in the right direction?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by anfetienne
            has anyone got any suggestions to point me in the right direction?
            the manual entry for sessions at php.net

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              ok i still keep getting a header error, i have removed the title as said and i get "Warning: Cannot modify header information - headers already sent by (output started at /home/theau10/public_html/resources/checklogin.php: 2) in /home/theau10/public_html/resources/checklogin.php on line 33" for the following code

              Code:
              <?php
              $username="theau10_tawUser";
              $password="auction10";
              $database="theau10_resources";
              
              // Connect to server and select databse.
              $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
              
              mysql_select_db("$database") or die("Unable to select database!");
              
              // username and password sent from form
              $myusername=$_POST['myusername'];
              $mypassword=$_POST['mypassword'];
              
              // To protect MySQL injection (more detail about MySQL injection)
              $myusername = stripslashes($myusername);
              $mypassword = stripslashes($mypassword);
              $myusername = mysql_real_escape_string($myusername);
              $mypassword = mysql_real_escape_string($mypassword);
              
              $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
              $result=mysql_query($sql);
              
              // Mysql_num_row is counting table row
              $count=mysql_num_rows($result);
              // If result matched $myusername and $mypassword, table row must be 1 row
              
              if($count==1){
              // Register $myusername, $mypassword and redirect to file "login_success.php"
              session_start();
              $_SESSION['myusername'] = $myusername;
              $_SESSION['mypassword'] = $mypassword;
              header("location: tsandcs.php");
              }
              else {
              header("location: incorrect.php");
              }
              ?>

              Comment

              Working...