postpone the sending of header information

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    postpone the sending of header information

    hi all.

    i am getting an error:
    [PHP]
    Warning: session_registe r() [function.sessio n-register]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\WTA \admin\login.ph p:14) in C:\wamp\www\WTA \admin\login.ph p on line 20
    [PHP]

    and two other similar header errors. so i think i need to somehow stop the sending of headers untill the end of my script if anyone can impart their wisdom on the matter i would be greatful

    eric
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    you always want to set header information at the top of your code

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      ok

      maybe my code isn't formated right. here is the code

      [PHP]
      <?
      $host="localhos t"; // Host name.
      $db_user="eric" ; // MySQL username.
      $db_password="d al4120"; // MySQL password.
      $database="wytr kcms"; // Database name.
      $cms = mysql_pconnect( $host, $db_user, $db_password) or trigger_error(m ysql_error(),E_ USER_ERROR);
      mysql_select_db ($database, $cms);
      if(isset($_POST[uname]))
      $user=$_POST[uname];
      if(isset($_POST[pass]))
      $pass=$_POST[pass];
      session_start() ;
      //session_destroy ();
      echo '1';
      $result=mysql_q uery("SELECT user, pass FROM users WHERE pass = '$pass' AND user='$user'");
      $row=mysql_fetc h_row($result);
      echo '2';
      if($row[0] == $user && $row[1] == $pass)
      {
      session_registe r("user");
      header("locatio n:index.php");
      }
      else
      {
      header("locatio n:login.htm");
      }

      ?>
      [/PHP]

      me error says the problem is occuring on session_registe r("user"); line and the one below it. or if the password is incoret then on the other redirect tag.
      do you know what i am doing wrong

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        remove those echo '0' and echo '1' lines, i don't know what is reason for those stuffs.since you are using them in this first the page try to print them, then you can't use the session_start() .
        and wrap the post element with single quotes.

        [PHP]if(isset($_GET['uname']))
        $user=$_GET['uname'];
        if(isset($_GET['pass']))
        $pass=$_GET['pass'];[/PHP]

        I change your script against to one of my table and it works.and redirected to index.htm with the values like this:
        http://localhost/thescripts/621150/session.php?una me=1016&pass=12 3
        Note that i used $_GET so do the changes. :)

        [PHP]<?
        $host="localhos t"; // Host name.
        $db_user="root" ; // MySQL username.
        $db_password="d ba"; // MySQL password.
        $database="test "; // Database name.
        $cms = mysql_pconnect( $host, $db_user, $db_password) or trigger_error(m ysql_error(),E_ USER_ERROR);
        mysql_select_db ($database, $cms);
        if(isset($_GET['uname']))
        $user=$_GET['uname'];
        if(isset($_GET['pass']))
        $pass=$_GET['pass'];
        session_start() ;
        //session_destroy ();
        //echo '1';
        $result=mysql_q uery("SELECT p_id, p_name FROM products WHERE p_id = '$user' AND p_name='$pass'" );
        $row=mysql_fetc h_row($result);
        //echo '2';
        if($row[0] == $user && $row[1] == $pass)
        {
        session_registe r("user");
        header("locatio n:index.php");
        }
        else
        {
        header("locatio n:login.htm");
        }

        ?> [/PHP]

        Comment

        • tolkienarda
          Contributor
          • Dec 2006
          • 316

          #5
          thanks
          i'll try those suggestions

          eric

          Comment

          Working...