NYCPHP Meetup

NYPHP.org

[nycphp-talk] url pass array as parameter

Anirudh Zala arzala at gmail.com
Tue Jul 1 00:13:58 EDT 2008


On Tuesday 01 Jul 2008 03:09:48 Tim Lieberman wrote:
> Passing arrays in a query string is the wrong way to do it.  Too many
> things can go wrong.

True. It is not proper way. But if you still want to pass such data using GET 
method then you can build Query string as shown below:

$cartStr='cart[0]=val1&cart[1]=val2';   // assuming that array keys are 
numeric.

This $cartStr string can be appended to URL where request is to be forwarded 
to. On that receiving page you can have that array in form of $_GET['cart']; 
which you can use for your purposes.

Remember if values in $cart is *sensitive* then neither GET nor POST is safe. 
Use session instead to store data on server only.

Anirudh Zala

>
> You could try creating a form, and sticking the serialize()d array
> value in to a hidden field.  Then POST the form to your gallery page.
>
> <?PHP
> echo '<form action="gallery.php" method="POST">
> <input type="hidden" name="cart" value="' . serialize($cart) . '"/>
> <input type="submit" value="Go To Gallery"/>
> </form>';
> ?>
>
> And in gallery.php
> <?PHP
> $cart = unserialize($_POST['cart']);
> ?>
>
> HTH
>
> -Tim
>
> On Jun 30, 2008, at 3:32 PM, chad qian wrote:
> > Hi,
> > I want to pass an unknow array cart[]: to "gallery" page through
> > url link:
> >
> > My url is:gallery.php?final=cart[]
> >
> > On gallery.php page
> > I want to output everything in this array
> >
> > My code is:
> > $finalcart=array();
> > $finalcart=$_get['final']
> > for(var i=0;i<sizeof($finalcart);i++)
> >    print finalcart[i];
> >
> >
> > Maybe my code is wrong.I only want to show my need.Can anyone help
> > me to correct my code?
> >
> > Thanks!
> >
> > chad
> >
> >
> > The other season of giving begins 6/24/08. Check out the i’m
> > Talkathon. Check it out!
> > _______________________________________________
> > New York PHP Community Talk Mailing List
> > http://lists.nyphp.org/mailman/listinfo/talk
> >
> > NYPHPCon 2006 Presentations Online
> > http://www.nyphpcon.com
> >
> > Show Your Participation in New York PHP
> > http://www.nyphp.org/show_participation.php





More information about the talk mailing list