FB group autoposter | jquery autocomplete ajax php mysql sample | jquery.autocomplete
 


 

Passing Array Variables using POST or GET with PHP



A convenient way to pass a single or multidimensional (possible utf-8) array is to serialize it ("convert it to a string") and pass it using a hidden input. After post or get, unserialize string variable, so the original array will be available.

How to serialize the array

Store the value in a hidden input. Try the following:

<input type="hidden"
	id="str_var"
	name="str_var"
	value="<?php print base64_encode(serialize($array_var)) ?>">;

Unserialize (after post or get)

Use something like this

$str_var = $_POST["str_var"];
$array_var = unserialize(base64_decode($str_var));

Encode URL

In case you have to create with code (e.g. javascript) the url to get, remember to encode it as a valid url:

<input type="hidden"
	id="str_var" name="str_var"
	value="<?php print urlencode(base64_encode(serialize($array_var))) ?>">;

References

From PHP docs

Hope to find it helpful. Your comments are welcomed!

Εγγραφή!
Sign-up for our free email newsletter. Get updates when new tutorials and tips are published. You can unsubscribe anytime with a click.

Your comments are welcomed!

This site actively encourages commenting on any post. Comments are not pre-moderated, but this community does not tolerate direct or indirect attacks, name-calling or insults. Please, read terms of use and Comment Policy at privacy policy.

More tips