Jump to content
Sign in to follow this  
Destramic

getting $_GET in a framework

Recommended Posts

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

 

 

Share this post


Link to post
Share on other sites

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 by bsmither

Share this post


Link to post
Share on other sites

Are you using URL rewriting? What do you have in place?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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]
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.