Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing objects and arrays using page.php?object=$object 1

Status
Not open for further replies.

BPMan

Programmer
Jun 25, 2002
163
US
i am going from one page to another when someone clicks on a link.
I would like to pass a couple of variables from one page to the other and i was trying to do this using the following method, the variable names are a and b.
page.php?a=$a&b=$b
this worked fine except when a or b is equal to a two or more word string like Tom Hanks
this would try to load
page.php?a=$a&b=$Tom Hanks
which is bad cause there is a space in the link...
so i tried to use an object and then an array to pass...
so i tried
$arr = array($a,$b);
page.php?arr=$arr
this does not seem to be working, either does, using an object.
it just passes junk.
what am doing wrong?
is there an easier way to do this?
thanks
 
pass variables by post.. in php, use $_POST['variablename'] to get those values..
 
what do you mean by pass them by post?
do i have to do anything or can i just say this in my new page...

$newa = $POST['a'];

this in my new page...
 
but this link is already inside a form that does other stuff...
can you have a form within a form?
 
another fool way i used b4 is using javascript to divide the array into a string.. use a ";" to separate each item.. anyway, a link cannot pass a object.. helpful?
 
As I see it you have a couple options IF you want to pass it via the URL, but realize the URL is limited because of length.

The easiest approach would be to
$a = urlencode($a);
$b = urlencode($b);

then put them in the URL and then

$a = urldecode($_GET['a']);
$b = urldecode($_GET['b']);

in the receiving script.



2) If you want to pass an object via the url it is completely possible in PHP as long as the object is small enough...

$a = serialize($arr);
$a = urlencode($a);
then put it into your URL
then on the receiving end

$a = urldecode($a);
$arr = unserialize($a);

Good luck,
Rob
 
in javascript, use escape().. for the space in your page.php?a=$a&b=$Tom Hanks


example:
newrule = escape(document.parent.F_AKT.value);
 
thanks rob that is exactly whay i was looking for...
 
You can just pass a space and it'll work, it'll change it to %20 automatically. Or is that just an IE thing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top