nadeemshafi9 Posted February 24, 2009 Share Posted February 24, 2009 hi guys im working with a function calld invoke that calls a function method in reflections i need to pass an array eg XML or JSON and title throgh a url i know i can seperate these with many different charachters and put it into a url what is the best way any examples much thanks Link to comment https://forums.phpfreaks.com/topic/146734-solved-best-way-to-pass-array-throgh-a-url-and-then-devide-into-different-variables-fun/ Share on other sites More sharing options...
rhodesa Posted February 24, 2009 Share Posted February 24, 2009 best way is to use POST with a Post Body. if GET is the only option, you can serialize() and rawurlencode() it, then unserialize() it on the other end Link to comment https://forums.phpfreaks.com/topic/146734-solved-best-way-to-pass-array-throgh-a-url-and-then-devide-into-different-variables-fun/#findComment-770347 Share on other sites More sharing options...
nadeemshafi9 Posted February 24, 2009 Author Share Posted February 24, 2009 best way is to use POST with a Post Body. if GET is the only option, you can serialize() and rawurlencode() it, then unserialize() it on the other end what would you serialise it with ? what character ? Link to comment https://forums.phpfreaks.com/topic/146734-solved-best-way-to-pass-array-throgh-a-url-and-then-devide-into-different-variables-fun/#findComment-770388 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 serialize it is a function. $array = array("item" => 1, 1 => "item"); $urlGET = rawurlencode(serialize($array)); header("Location: page.php?array={$urlGET}"); However, I would prefer to use POST or even sessions (if the page is on your server) to do this. To separate each item to avoid serialization: (The below assumes an associative array, with the index being the "variable" name.) $getData = array(); foreach ($array as $key => $val) { $getData[] = "{$key}={$val}"; } $urlQueryString = implode("&", $getData); header("Location: page.php?{$urlQueryString}"); Link to comment https://forums.phpfreaks.com/topic/146734-solved-best-way-to-pass-array-throgh-a-url-and-then-devide-into-different-variables-fun/#findComment-770393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.