Skip to content

Instantly share code, notes, and snippets.

@vdite
Last active August 28, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdite/79919fa33a3e4fbf505c to your computer and use it in GitHub Desktop.
Save vdite/79919fa33a3e4fbf505c to your computer and use it in GitHub Desktop.
How to transfer an Array over URL GET Parameters
<?php
/* array_over_get.php */
$image_arr=array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg");
$serial_arr=urlencode(base64_encode(serialize($image_arr)));
echo '<img src="process_images.php?arr='.$serial_arr.'" alt="stacked image"/>';
?>
<?php
/* process_images.php */
$image_arr=unserialize(base64_decode(urldecode($_GET['arr'])));
foreach($image_arr as $value){
/* do anything here
* just as an example
* https://gist.github.com/vdite/30644e28301916789ff5
*/
}
?>
@vdite
Copy link
Author

vdite commented May 8, 2014

Why use of base64 encoding? URLencoding on a string is a waste of space and you only have 4k. http://stackoverflow.com/a/8594760/2099411

BUT, base64 encode may have +=/ characters, that have to be translated with urlencode

@vdite
Copy link
Author

vdite commented May 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment