Jump to content

getting $_GET in a framework


Destramic
Go to solution Solved by trq,

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

 

 

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • Solution

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.