By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,530 Members | 2,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,530 IT Pros & Developers. It's quick & easy.

Passing vars in a link ?

P: n/a
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.php?data=$data'>go 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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Pjotr Wedersteers" wrote:
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.php?data=$data’>go
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


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
Jul 17 '05 #2

P: n/a
"Pjotr Wedersteers" <x3****@westerterp.com> wrote in message
news:<41***********************@news.xs4all.nl>...

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.php?data=$data'>go 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?
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(serialize($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(urldecode($_POST['data']));
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 ?
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.
How long a string can be passed as a single var ?
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.
Different for GET vs POST ?


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

Cheers,
NC
Jul 17 '05 #3

P: n/a
Nikolai Chuvakhin wrote:
"Pjotr Wedersteers" <x3****@westerterp.com> wrote in message
news:<41***********************@news.xs4all.nl>...

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.php?data=$data'>go 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?


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(serialize($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(urldecode($_POST['data']));
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 ?


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.
How long a string can be passed as a single var ?


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.
Different for GET vs POST ?


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

Cheers,
NC


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
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.