Header

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

    Header

    hi all

    I'm having trouble getting something simple working and can't see why.

    This is the code I'm running:

    <?php if ($row_Recordset 1['type']=="agent"){

    header("Locatio n: agentindex.php" );
    echo "AGENT";
    exit;
    }

    else
    {
    header("Locatio n: llindex.php");
    echo "LANDLORD";
    exit;
    }

    ?>
  • Andy Barfield

    #2
    Re: Header

    AJ wrote:[color=blue]
    > I'm having trouble getting something simple working and can't see why.[/color]
    Are you getting errors? If so, what are they?
    [color=blue]
    > header("Locatio n: agentindex.php" );[/color]
    This will force most browsers to redirect immediately. You should also
    specify the full URI, rather than the file name alone.
    [color=blue]
    > echo "AGENT";[/color]
    This may never be executed, or rather may never be seen inthe browser as
    it will be replaced with the page to which you have just redirected.
    [color=blue]
    > header("Locatio n: llindex.php");
    > echo "LANDLORD";[/color]
    Likewise

    If you are getting headers already sent errors, you script is outputting
    something before the location call (even one white space character).

    Check the manual for Output control and for headers:



    Hope this helps, regards,

    Andy

    Comment

    • AJ

      #3
      Re: Header


      "Andy Barfield" <abarfield_01@y ahoo.com> wrote in message
      news:q6-dnSZ35eGYK43cRV n-pQ@nildram.net. ..[color=blue]
      > AJ wrote:[color=green]
      > > I'm having trouble getting something simple working and can't see why.[/color]
      > Are you getting errors? If so, what are they?[/color]

      I've actually managed to sort it. I've found two things to watch out for:

      1. Probably obvious, but it wasn't to me. I'd put the PHP with the header
      information inside the <BODY> of the page
      2. It would appear that any white space after the header call messes things
      up. Even a space after the ; will cause it not to work

      Does that sound feasible?

      Andy


      Comment

      • Andy Barfield

        #4
        Re: Header

        Sorry - been away for a couple of days, didn't see your reply.

        AJ wrote:[color=blue]
        > 1. Probably obvious, but it wasn't to me. I'd put the PHP with the header
        > information inside the <BODY> of the page[/color]
        Yep, that would do it - the headers must be sent before any other output
        to the browser, even a space before the <?php tag will stop it working
        and give you a "headers already sent" error.
        [color=blue]
        > 2. It would appear that any white space after the header call messes things
        > up. Even a space after the ; will cause it not to work[/color]
        Not seen that happen before. I often use the Location header in an
        if-else block like

        if(!something)
        {
        header("Locatio n: http://somewhere.else/");
        exit;
        }
        else
        {
        echo "I have not reditected you";
        }

        Regards,

        Andy

        Comment

        Working...