Passing vars in a link ?

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

    #1

    Passing vars in a link ?

    Hello again,

    I have now several consecutive forms in my site which nicely pass variables
    in POST, so they won't show up in the header.
    Now I have a page people reach after submitting all kinds of information,
    from where I offer a link users can click on.
    Let's say I have collected several strings and I have put these in an array
    and serialized that.

    $var[0]='John Doe';
    $var[1]='2345 Livnigston Ave';
    $var[2]='Boston';
    $var[3]='Plumber';
    $data = serialize ($var);

    When the user clicks the (only) link on this page, all this serialized data
    needs to be passed along to the new page.
    I did this:

    (...)
    // $data contains the serialized array
    echo "<a href='action.ph p?data=$data'>g o here</a>";

    First question: using this method the $data is passed via GET. I would
    prefer to keep using POST, and not have ugly tell-tale headers. Is that
    possible using PHP? How? [I'd rather not use sessions here which would avoid
    the entire datapassing issue.]

    Second question: when I echo back $data in the action.php script, it seems a
    chunk of the string is missing. Is that due to a limit in length ? How long
    a string can be passed as a single var ? Different for GET vs POST ? Like it
    is unserialize returns FALSE, which makes sense, as the data is incomplete.

    Help appreciated. If you need more specifics, I'm happy to elaborate.
    Pjotr


  • steve

    #2
    Re: Passing vars in a link ?

    "Pjotr Wedersteers" wrote:[color=blue]
    > Hello again,
    >
    > I have now several consecutive forms in my site which nicely pass
    > variables
    > in POST, so they won’t show up in the header.
    > Now I have a page people reach after submitting all kinds of
    > information,
    > from where I offer a link users can click on.
    > Let’s say I have collected several strings and I have put these
    > in an array
    > and serialized that.
    >
    > $var[0]=’John Doe’;
    > $var[1]=’2345 Livnigston Ave’;
    > $var[2]=’Boston’;
    > $var[3]=’Plumber’;
    > $data = serialize ($var);
    >
    > When the user clicks the (only) link on this page, all this[/color]
    serialized[color=blue]
    > data
    > needs to be passed along to the new page.
    > I did this:
    >
    > (...)
    > // $data contains the serialized array
    > echo "<a href=’action.ph p?data=$data’>g o
    > here</a>";
    >
    > First question: using this method the $data is passed via GET. I[/color]
    would[color=blue]
    > prefer to keep using POST, and not have ugly tell-tale headers. Is
    > that
    > possible using PHP? How? [I’d rather not use sessions here which
    > would avoid
    > the entire datapassing issue.]
    >
    > Second question: when I echo back $data in the action.php script,[/color]
    it[color=blue]
    > seems a
    > chunk of the string is missing. Is that due to a limit in length ?[/color]
    How[color=blue]
    > long
    > a string can be passed as a single var ? Different for GET vs POST[/color]
    ?[color=blue]
    > Like it
    > is unserialize returns FALSE, which makes sense, as the data is
    > incomplete.
    >
    > Help appreciated. If you need more specifics, I’m happy to
    > elaborate.
    > Pjotr[/color]

    Question 1: Instead of using a link, you have the option of using a
    button (if that is ok) and put that in a form and use post.

    Question 2: I am not sure, but make sure to urlencode your serialized
    string when attaching it to url.

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-Passing-...ict145063.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=485854

    Comment

    • Nikolai Chuvakhin

      #3
      Re: Passing vars in a link ?

      "Pjotr Wedersteers" <x33159@westert erp.com> wrote in message
      news:<4134a5e0$ 0$78753$e4fe514 c@news.xs4all.n l>...[color=blue]
      >
      > I have now several consecutive forms in my site which nicely pass variables
      > in POST, so they won't show up in the header.
      > Now I have a page people reach after submitting all kinds of information,
      > from where I offer a link users can click on.
      > Let's say I have collected several strings and I have put these in an array
      > and serialized that.
      >
      > $var[0]='John Doe';
      > $var[1]='2345 Livnigston Ave';
      > $var[2]='Boston';
      > $var[3]='Plumber';
      > $data = serialize ($var);
      >
      > When the user clicks the (only) link on this page, all this serialized data
      > needs to be passed along to the new page.
      > I did this:
      >
      > (...)
      > // $data contains the serialized array
      > echo "<a href='action.ph p?data=$data'>g o here</a>";
      >
      > First question: using this method the $data is passed via GET. I would
      > prefer to keep using POST, and not have ugly tell-tale headers. Is that
      > possible using PHP?[/color]

      Sure. Just replace the link with a form, and don't forget to
      urlencode() the serialized array:

      $var[0]='John Doe';
      $var[1]='2345 Livnigston Ave';
      $var[2]='Boston';
      $var[3]='Plumber';
      $data = urlencode(seria lize($var));
      echo <<<ENDOFFORM
      <form method="post" action="action. php">
      <input type="hidden" name="data" value="$data">
      <input type="submit" value="Go!">
      </form>
      ENDOFFORM;

      And in action.php, you can do:

      $var = unserialize(url decode($_POST['data']));
      [color=blue]
      > when I echo back $data in the action.php script, it seems a
      > chunk of the string is missing. Is that due to a limit in length ?[/color]

      Most likely, it is due to the fact that you didn't urlencode() the
      serialized array, so spaces, double quotes, colons, and semicolons
      conspired to mess up your variable.
      [color=blue]
      > How long a string can be passed as a single var ?[/color]

      I don't think this is a right question to ask. If I remember correctly,
      there is a limit to the number of characters in a GET request.
      [color=blue]
      > Different for GET vs POST ?[/color]

      Definitely. POST requests can be much longer than GET requests.

      Cheers,
      NC

      Comment

      • Pjotr Wedersteers

        #4
        Re: Passing vars in a link ?

        Nikolai Chuvakhin wrote:[color=blue]
        > "Pjotr Wedersteers" <x33159@westert erp.com> wrote in message
        > news:<4134a5e0$ 0$78753$e4fe514 c@news.xs4all.n l>...[color=green]
        >>
        >> I have now several consecutive forms in my site which nicely pass
        >> variables in POST, so they won't show up in the header.
        >> Now I have a page people reach after submitting all kinds of
        >> information, from where I offer a link users can click on.
        >> Let's say I have collected several strings and I have put these in
        >> an array and serialized that.
        >>
        >> $var[0]='John Doe';
        >> $var[1]='2345 Livnigston Ave';
        >> $var[2]='Boston';
        >> $var[3]='Plumber';
        >> $data = serialize ($var);
        >>
        >> When the user clicks the (only) link on this page, all this
        >> serialized data needs to be passed along to the new page.
        >> I did this:
        >>
        >> (...)
        >> // $data contains the serialized array
        >> echo "<a href='action.ph p?data=$data'>g o here</a>";
        >>
        >> First question: using this method the $data is passed via GET. I
        >> would prefer to keep using POST, and not have ugly tell-tale
        >> headers. Is that possible using PHP?[/color]
        >
        > Sure. Just replace the link with a form, and don't forget to
        > urlencode() the serialized array:
        >
        > $var[0]='John Doe';
        > $var[1]='2345 Livnigston Ave';
        > $var[2]='Boston';
        > $var[3]='Plumber';
        > $data = urlencode(seria lize($var));
        > echo <<<ENDOFFORM
        > <form method="post" action="action. php">
        > <input type="hidden" name="data" value="$data">
        > <input type="submit" value="Go!">
        > </form>
        > ENDOFFORM;
        >
        > And in action.php, you can do:
        >
        > $var = unserialize(url decode($_POST['data']));
        >[color=green]
        >> when I echo back $data in the action.php script, it seems a
        >> chunk of the string is missing. Is that due to a limit in length ?[/color]
        >
        > Most likely, it is due to the fact that you didn't urlencode() the
        > serialized array, so spaces, double quotes, colons, and semicolons
        > conspired to mess up your variable.
        >[color=green]
        >> How long a string can be passed as a single var ?[/color]
        >
        > I don't think this is a right question to ask. If I remember
        > correctly, there is a limit to the number of characters in a GET
        > request.
        >[color=green]
        >> Different for GET vs POST ?[/color]
        >
        > Definitely. POST requests can be much longer than GET requests.
        >
        > Cheers,
        > NC[/color]

        Amazing how one often misses the easiest of things. Never thought of a form
        with just a hidden field.
        Cleared it all up for me, thanks a bunch really, Nikolai! You rock.
        regards
        Pjotr


        Comment

        Working...