Destramic Posted December 21, 2014 Share Posted December 21, 2014 hey guys im having a bit of trouble getting $_GET in my framework. now the ony way to get query from a url such as: users/activate-account?email_address=test&token=test i have to use $_SERVER['REQUEST_URI'] unless im doing something wrong? [REQUEST_URI] => /bisi/user/activate-account?email_address=test&token=test by doing this: print_r($_GET); all i get is : Array ( [uri] => user/activate-account ) just concerned im doing something wrong?...any advise on this please guys. was thinking of doing something like this in my request public function get_query($name = null) { $uri = $_SERVER['REQUEST_URI']; if (parse_url($uri, PHP_URL_QUERY)) { $query = explode("?", $uri); $query = explode("&", $query[1]); $array = array(); foreach ($query as $string) { $string = explode("=", $string); $query_name = $string[0]; $query_value = $string[1]; $array[$query_name] = $query_value; // $_GET[$query_name] = $query_value; possibly? } if ($name !== null && array_key_exists($name, $array)) { return $array[$name]; } return $array; } return null; } thanks Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/ Share on other sites More sharing options...
bsmither Posted December 21, 2014 Share Posted December 21, 2014 (edited) The values in $_GET is strange, no doubt. Perhaps spending some time trying to understand why that is happening. In the meantime, this may be a (less-than-ideal) work-around: $tmp1 = explode("?", $uri); // should give array([0] => '/bisi/user/activate-account', [1] => 'email_address=test&token=test') $tmp2 = explode("&",$tmp1[1]); // should give array([0] => 'email_address=test', [1] => 'token=test') foreach($tmp2 as $querystringKeyVal) { etc. Edited December 21, 2014 by bsmither Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500310 Share on other sites More sharing options...
requinix Posted December 22, 2014 Share Posted December 22, 2014 Are you using URL rewriting? What do you have in place? Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500315 Share on other sites More sharing options...
Destramic Posted December 22, 2014 Author Share Posted December 22, 2014 this is what im using...is there a way of doing things better here to get $_GET as it should be? Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?uri=$1 [PT,L] thanks Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500326 Share on other sites More sharing options...
trq Posted December 22, 2014 Share Posted December 22, 2014 That rewrite rule removes the need for typical GET parameters by making your urls "pretty". So instead of this: users/activate-account?email_address=test&token=test You would use something more like: users/activate-account/test/test Of course then you need some sort of "router" to parse and handle these parameters for you. If this is your own framework you need to decide how your urls are going to be formed. Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500330 Share on other sites More sharing options...
Destramic Posted December 22, 2014 Author Share Posted December 22, 2014 Is there a way of accomplishing what I need in a rewrite? Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500331 Share on other sites More sharing options...
Solution trq Posted December 22, 2014 Solution Share Posted December 22, 2014 The point I'm trying to make is why have the rewrite at all if you're just going to use normal querystring parameters? I understand you want to force everything through a front controller, but why stop there? But yeah, you could just use the QSA flag to have apache append existing parameters. RewriteRule ^(.*)$ index.php?uri=$1 [PT,L,QSA] 1 Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500332 Share on other sites More sharing options...
Destramic Posted December 24, 2014 Author Share Posted December 24, 2014 worked great thank you Quote Link to comment https://forums.phpfreaks.com/topic/293219-getting-_get-in-a-framework/#findComment-1500541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.