Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stndn

macrumors member
Oct 22, 2006
80
1
earth
Do you have to use cookies? Or is session an option for you?

Care to let us know what you've tried so far?
Maybe we can point out where you made your mistakes (if any)


-stndn.
 

oaze

macrumors newbie
May 7, 2007
1
0
passing an array

You have several possibilities, which all has advantages and disadvantages.

  • save in cookie
  • save in session
  • send in a form
  • send as parameter in a link

You have to think first about the sensitivity of the information you pass to next page, is it important that no one can tamper with the information ? .. if so, you can rule out cookie, form or link.

Do you only need info once or through out the whole user session ?
usually Sessions and cookies are used for persistant information, and forms and d parameters sent via link are used for inforrmation that are just pased from one page to another.

Anyway, a convenient method for passing the array is first turning array into a string, using a delimiter to separate each of the components of the array.:

$comma_separated = implode(",", $array);

Then on the next page you turn it into an array again:

$array_again = explode(",", $comma_separated);

The string can either be sent in a hidden filed in a form, or as parameter on a link. The last you might need to URLencode it.

also if security is an issue, you could add a checksum of a kind to array passed, and check for consistancy on the next page.

hope that this helps you...

kind regards
/sonny
 

stndn

macrumors member
Oct 22, 2006
80
1
earth
Actually, instead of combining the values into string, you may want to look into serialize and unserialize.
Using a delimiter will require you to find out a character that is not used anywhere in your array values to avoid separating the values incorrectly.

Just be careful of the extra backslashes that may be added to the serialized string, which all depends on your server's PHP settings.

oaze is right, though.
The first question to ask is: How important is it for you to keep the information safe and secured?


-stndn.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.