Include and Header(Location: ) not working together

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geshan

    #1

    Include and Header(Location: ) not working together

    In php5 I am not able to use include funciton and header("locatio n:"""
    together please help.

  • Alvaro G. Vicario

    #2
    Re: Include and Header(Location : ) not working together

    *** geshan escribió/wrote (26 Aug 2006 22:36:45 -0700):
    In php5 I am not able to use include funciton and header("locatio n:"""
    together please help.
    In what sense aren't you able? I mean, you just type the code as usual,
    don't you? What prevents you from doing so?

    I'll make an exercise of fortune telling. You've upgraded to PHP 5 and you
    are using the default settings in php.ini, where display_errors is
    disabled. Enable it this way:

    display_errors = On
    error_reporting = E_ALL

    When you do so, the PHP interpreter will say you cannot insert a header
    because output already started. You cannot print anything into the page
    before using the header() function. That includes blank lines outside the
    <?php ?tags.


    --
    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    ++ Mi sitio sobre programación web: http://bits.demogracia.com
    +- Mi web de humor con rayos UVA: http://www.demogracia.com
    --

    Comment

    • geshan

      #3
      Re: Include and Header(Location : ) not working together


      these are the errors i get,

      Warning: session_start() [function.sessio n-start]: Cannot send session
      cookie - headers already sent by (output started at
      D:\Xampp\xampp\ htdocs\GM_PHP\i ncludes\conn1.p hp:11) in
      D:\Xampp\xampp\ htdocs\GM_PHP\l ogin_process.ph p on line 2

      Warning: session_start() [function.sessio n-start]: Cannot send session
      cache limiter - headers already sent (output started at
      D:\Xampp\xampp\ htdocs\GM_PHP\i ncludes\conn1.p hp:11) in
      D:\Xampp\xampp\ htdocs\GM_PHP\l ogin_process.ph p on line 2

      Warning: Cannot modify header information - headers already sent by
      (output started at D:\Xampp\xampp\ htdocs\GM_PHP\i ncludes\conn1.p hp:11)
      in D:\Xampp\xampp\ htdocs\GM_PHP\l ogin_process.ph p on line 38

      i'm using xampp with php, Apache 2.2 and mysql 4.01

      I'm posting the login_process.p hp file here, it is made for a login
      system plesae help:

      <?php
      session_start() ;
      include("includ es/conn1.php");
      ?>
      <?php
      if(isset($_POST['Submit']))
      {
      $username=$_POS T['txtusername'];
      $password_frm=$ _POST['txtpassword'];
      //$users_in='';

      if(!empty($user name) && !empty($passwor d_frm))
      {

      $sql="SELECT password FROM tbl_users WHERE user_name = '$username'
      and user_status=1";
      $users_in=mysql _query($sql) or die(mysql_error ());
      $pass_db=mysql_ result($users_i n,0,0);

      /*while($user_va lid=mysql_fetch _array($users_i n))
      {
      //echo $user_valid['password'];
      $pass_db= $user_valid['password'];
      }

      //still left to validate password
      //while(
      //$user_data=mysq l_fetch_array($ users_in);
      //extract($user_i n); */

      if($pass_db==$p assword_frm)
      {
      //set session
      $_SESSION['logged_in_user name']=$username;
      $_SESSION['user_status']="valid";

      header("Locatio n:logged_in.php ");
      //echo "logged in.";
      }
      else
      {
      header("Locatio n:login.php?msg =pwerror");
      //echo "Invalid PW.";
      //echo $users_in['password'];
      }
      }
      else
      {
      header("Locatio n:login.php?msg =blank");
      //echo "Error. blank";
      }
      }
      else
      {
      header("Locatio n:login.php?msg =illegal");
      //echo "Empty not allowed.";
      }
      ?>

      The Code of conn1.php

      <?php

      $con=mysql_conn ect("localhost" ,"root","") or die(mysql_error ());

      mysql_select_db ("gesDB",$co n);

      //echo 'conncection succesful.';

      ?>

      I need help. Please Help Fast

      Comment

      • Jerry Stuckle

        #4
        Re: Include and Header(Location : ) not working together

        geshan wrote:
        these are the errors i get,
        >
        Warning: session_start() [function.sessio n-start]: Cannot send session
        cookie - headers already sent by (output started at
        D:\Xampp\xampp\ htdocs\GM_PHP\i ncludes\conn1.p hp:11) in
        D:\Xampp\xampp\ htdocs\GM_PHP\l ogin_process.ph p on line 2
        >
        Warning: session_start() [function.sessio n-start]: Cannot send session
        cache limiter - headers already sent (output started at
        D:\Xampp\xampp\ htdocs\GM_PHP\i ncludes\conn1.p hp:11) in
        D:\Xampp\xampp\ htdocs\GM_PHP\l ogin_process.ph p on line 2
        >
        Warning: Cannot modify header information - headers already sent by
        (output started at D:\Xampp\xampp\ htdocs\GM_PHP\i ncludes\conn1.p hp:11)
        in D:\Xampp\xampp\ htdocs\GM_PHP\l ogin_process.ph p on line 38
        >
        <code snipped>
        >
        I need help. Please Help Fast
        >
        Just like it said - line 11 of includes\conn1. php is causing output to
        be sent to the browser. This forces the headers to be sent to the
        browser. session_start() must be called before ANY output is sent to
        the browser.

        The output could be from an echo or print statement, for instance. Or
        it could be just whitespace outside of the <?php ... ?brackets. Any
        output will cause the headers to be sent.

        The only confusing factor here is that you don't include
        include\conn1.p hp until after the session_start() command. It looks
        like this isn't your exact code, or perhaps your login_process.p hp is
        itself included in another file.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • geshan

          #5
          Re: Include and Header(Location : ) not working together


          Dear Jerry,
          Thank you very much but i solved the problem. The problem was n
          conn1.php where i have left three blank lines after the code that was
          causing the errors.

          Geshan.

          Comment

          Working...