Skip to content

Instantly share code, notes, and snippets.

@Ultrabenosaurus
Created August 7, 2012 11:25
Show Gist options
  • Save Ultrabenosaurus/3284643 to your computer and use it in GitHub Desktop.
Save Ultrabenosaurus/3284643 to your computer and use it in GitHub Desktop.
A simple method to maintain current querystring when redirecting. Needed it for a WP plugin I'm making.
function get_join(){
$keys = array_keys($_GET);
$url = '?';
$first = true;
for($i = 0; $i < count($keys); $i++){
if(!$first){
$url .= '&';
}
$url .= $keys[$i].'='.$_GET[$keys[$i]];
$first = false;
}
return $url;
}
@hatsuseno
Copy link

Why bother with something this cumbersome and easily breakable?

function get_join() {
  return '?' . http_build_query($_GET);
}

@Ultrabenosaurus
Copy link
Author

I had no idea that function existed, I feel silly now :/

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