redirect

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

    redirect

    Hi,

    What's wrong with that?

    I have a variable

    $order_nummer = "C.45";

    Then I redirect to

    header('Locatio n: xmlorderon.php? order_id=$order _nummer');

    but I my location bar I see:

    http://localhost/pcGebruik/files/xmlorderon.php? order_id=$order _nummer


    thx
    Alain


  • Jerry

    #2
    Re: redirect

    Use double quotes instead.
    " instead of ' in your header argument.


    On Wed, 4 Feb 2004 11:24:53 +0100, "alain dhaene"
    <a.dhaene@instr uct.be> wrote:
    [color=blue]
    >Hi,
    >
    >What's wrong with that?
    >
    >I have a variable
    >
    >$order_numme r = "C.45";
    >
    >Then I redirect to
    >
    >header('Locati on: xmlorderon.php? order_id=$order _nummer');
    >
    >but I my location bar I see:
    >
    >http://localhost/pcGebruik/files/xmlorderon.php? order_id=$order _nummer
    >
    >
    >thx
    >Alain
    >[/color]

    Comment

    • Pedro Graca

      #3
      Re: redirect

      alain dhaene wrote:[color=blue]
      > I have a variable
      >
      > $order_nummer = "C.45";
      >
      > Then I redirect to
      >
      > header('Locatio n: xmlorderon.php? order_id=$order _nummer');
      >
      > but I my location bar I see:
      >
      > http://localhost/pcGebruik/files/xmlorderon.php? order_id=$order _nummer[/color]

      The contents of single quotes are taken literally (with two exceptions).

      echo 'the variable a holds $a'; // taken literally
      echo 'it\'s a exception'; // the \' is taken as a single '
      echo 'the other exception is \\ a single backslash';


      So to have your header() do what you want either use double quotes
      (which interpolate much more than single quotes) or concatenate the
      contents of $order_nummer to the rest of the URL:

      header('Locatio n: xmlorderon.php? order_id=' . $order_nummer);

      Better yet is to use urlencode() for the $order_nummer:

      header('Locatio n: xmlorderon.php? order_id=' . urlencode($orde r_nummer));
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • Matthias Esken

        #4
        Re: redirect

        Pedro Graca <hexkid@hotpop. com> schrieb:
        [color=blue]
        > Better yet is to use urlencode() for the $order_nummer:
        >
        > header('Locatio n: xmlorderon.php? order_id=' . urlencode($orde r_nummer));[/color]

        And even better would be the use of a valid syntax for the location.

        header('Locatio n: http://www.example.com/xmlorderon.php? order_id=' .
        urlencode($orde r_nummer));

        According to http://www.php.net/manual/en/function.header.php HTTP/1.1
        requires an absolute URI as argument to Location: including the scheme,
        hostname and absolute path, but some clients accept relative URIs. So
        with the short version it might work on some clients and fail on others
        and that's not what you want. :-) Use the correct version and it will
        run anywhere.

        Regards,
        Matthias

        Comment

        • Pedro Graca

          #5
          Re: redirect

          Matthias Esken wrote:[color=blue]
          > And even better would be the use of a valid syntax for the location.
          >
          > header('Locatio n: http://www.example.com/xmlorderon.php? order_id=' .
          > urlencode($orde r_nummer));[/color]

          Right. Thank you for the correction.

          The W3C (World Wide Web Consortium) says the same thing about the
          Location: header:

          --
          --= my mail box only accepts =--
          --= Content-Type: text/plain =--
          --= Size below 10001 bytes =--

          Comment

          • Pedro Graca

            #6
            Re: redirect

            Pedro Graca wrote:[color=blue]
            > Right. Thank you for the correction.[/color]

            Where it is written "correction ", please read "revision and update"
            --
            --= my mail box only accepts =--
            --= Content-Type: text/plain =--
            --= Size below 10001 bytes =--

            Comment

            Working...