header (Location: ) not working on web server

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

    header (Location: ) not working on web server

    I have a simple php page in which I use

    header("Locatio n: http://www.example.com/");

    to redirect the user to another php page. The php script works on my
    local machine but when I upload it to the web server for hosting the
    redirection does not work. Instead on one server it gives the standard
    header error

    Warning: Cannot modify header information - headers already sent
    by .......

    while on the other server, I dont see this error but it also does not
    redirect just refreshes the page when I click the Submit button.

    Does anybody know how can i resolve this?
    Thanks

  • Erwin Moller

    #2
    Re: header (Location: ) not working on web server

    php newbie wrote:
    I have a simple php page in which I use
    >
    header("Locatio n: http://www.example.com/");
    >
    to redirect the user to another php page. The php script works on my
    local machine but when I upload it to the web server for hosting the
    redirection does not work. Instead on one server it gives the standard
    header error
    >
    Warning: Cannot modify header information - headers already sent
    by .......
    >
    while on the other server, I dont see this error but it also does not
    redirect just refreshes the page when I click the Submit button.
    >
    Does anybody know how can i resolve this?
    Thanks
    Yes,

    On one server you created output before using hedaer(), and on the other
    not.
    You cannot use header if you send information already.

    Possibly you have an error/notice/warning/whatever on 1 server (and thus
    produce output) and not on the other?

    Regards,
    Erwin Moller

    Comment

    • php newbie

      #3
      Re: header (Location: ) not working on web server

      Hello Erwin, I did not understand your response. Its the same php
      page, why is it showing the warning on one server and not on another
      and why is the same page working on my local machine and not working
      when I upload it to the server.
      I would really appreciate your help, I am a newbie to php and not
      aware of any configuration settings that I might need to change.
      Thanks


      Comment

      • Martin Mandl - m2m tech support

        #4
        Re: header (Location: ) not working on web server

        On Feb 7, 5:35 pm, "php newbie" <arpit...@gmail .comwrote:
        Hello Erwin, I did not understand your response. Its the same php
        page, why is it showing the warning on one server and not on another
        and why is the same page working on my local machine and not working
        when I upload it to the server.
        I would really appreciate your help, I am a newbie to php and not
        aware of any configuration settings that I might need to change.
        Thanks
        Redirecting with the header functions works only if no output has been
        produced before this command. If you are using the same files on both
        servers it could be that the settings of those servers are different.

        E.g. If your first server is configured to show no warnings (e.g. when
        a variable is used without being defined before) and the second server
        is configured to show those warnings, it will work on the first server
        but will not on the second.

        In this case a workaround would be to use the same configurations, or
        to clear up your code in order to produce no warnings.

        Good luck
        Martin

        ------------------------------------------------
        online accounting on bash bases
        Online Einnahmen-Ausgaben-Rechnung

        ------------------------------------------------
        m2m server software gmbh



        Comment

        • Michael Fesser

          #5
          Re: header (Location: ) not working on web server

          ..oO(php newbie)
          >Hello Erwin, I did not understand your response. Its the same php
          >page, why is it showing the warning on one server and not on another
          >and why is the same page working on my local machine and not working
          >when I upload it to the server.
          Check the output of phpinfo(). It looks like on your machine output
          buffering is enabled by default (output_bufferi ng = 1).
          >I would really appreciate your help, I am a newbie to php and not
          >aware of any configuration settings that I might need to change.
          You should try to fix the problem instead. Don't send any output to the
          browser before the header() call. The error message shows where the
          output started.

          Micha

          Comment

          • php newbie

            #6
            Re: header (Location: ) not working on web server

            Thanks all for valuable inputs, I will try phpinfo() function tonight.
            What could be the reason for code to be working on my local machine
            and not working on the web server.

            Following is the pseudo code of what my php page looks like

            ---- temp1.php --------
            <html>
            <head>


            </head>
            <body>
            <?php

            // test if this is postback
            // if this is postback
            // create session and write form fields to the session
            // call header(Location : ) function to redirect to temp2.php page

            ?>

            <form method="post" action="temp1.p hp" >

            // form input fields

            <input type="submit" value="Submit" >
            </form>
            </body>
            </html>


            Comment

            • Jonathan N. Little

              #7
              Re: header (Location: ) not working on web server

              php newbie wrote:
              Thanks all for valuable inputs, I will try phpinfo() function tonight.
              What could be the reason for code to be working on my local machine
              and not working on the web server.
              >
              Following is the pseudo code of what my php page looks like
              >
              ---- temp1.php --------
              <html>
              <head>
              >
              >
              </head>
              <body>
              The "<html><hea d></head><bodystuff *cannot* be above your header call
              that flows...
              <?php
              >
              // test if this is postback
              // if this is postback
              // create session and write form fields to the session
              // call header(Location : ) function to redirect to temp2.php page
              >
              ?>
              >
              <form method="post" action="temp1.p hp" >
              >
              // form input fields
              >
              <input type="submit" value="Submit" >
              </form>
              </body>
              </html>

              ---- temp1.php -------- Should be:

              <?php
              //do what ever testing you want to determine if you want to redirect
              if( $redirect_condi tion == TRUE ){
              //put redirect here
              header("Locatio n: http://www.example.com/temp2.php");
              }
              //if your not redirecting then put your page below
              ?>
              <html>
              <head>...



              --
              Take care,

              Jonathan
              -------------------
              LITTLE WORKS STUDIO

              Comment

              • Michael Fesser

                #8
                Re: header (Location: ) not working on web server

                ..oO(php newbie)
                >Thanks all for valuable inputs, I will try phpinfo() function tonight.
                >What could be the reason for code to be working on my local machine
                >and not working on the web server.
                As said: different configuration.

                Micha

                Comment

                • php newbie

                  #9
                  Re: header (Location: ) not working on web server

                  Thanks Jonathan, that solved the problem .... :-)

                  Thanks everybody else for their inputs.....
                  good night !!!!

                  Comment

                  Working...