To pass an array in a url use the following:
1 | <?php $serialized = rawurlencode(serialize($args)); ?> |
2 | <a href="testpage.php?args=<!--?php echo $args ?-->">Test Page</a> |
To retrieve the array use the following:
1 | <?php $args = unserialize(stripslashes(rawurldecode($_GET['args']))); ?> |
Here is an explination of whats going on:
7 | $serialized = rawurlencode(serialize($args)); |
<a href=”testpage.php?args=“>Test Page</a>
2 | testpage.php?args=a%3A3%3A{s%3A3%3A%22bid%22%3Bi%3A2%3Bs%3A3%3A%22pid%22%3Bi%3A1806%3Bs%3A3%3A%22mid%22%3Bb%3A1%3B} |
var_dump(rawurldecode($_GET[‘args’])));
2 | string(57) "a:3:{s:3:\"bid\";i:2;s:3:\"pid\";i:1806;s:3:\"mid\";b:1;}" |
var_dump(stripslashes(rawurldecode($_GET[‘args’]))));
2 | string(51) "a:3:{s:3:"bid";i:2;s:3:"pid";i:1806;s:3:"mid";b:1;}" |
var_dump(unserialize(stripslashes(rawurldecode($_GET[‘args’]))));
3 | array(3) { ["bid"]=> int(2) ["pid"]=> int(1806) ["mid"]=> bool(true) } |