Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there no need to use $_GET['varName'] when using htaccess?

Tags:

php

.htaccess

I just wrote a htaccess file and a simple rule.

RewriteRule ^/?([a-z]{2})/([0-9]{4})/?$ /run/run.php?country=$1&year=$2 [NC,L]
This does http://www.localhost/us/2014

On the php page, I accidently did:

echo $country.' '.$year;

This gave me the output below, which is correct.

us 2014

I did not do:

$country = $_GET['country'];
$year = $_GET['year'];

But it still worked. Is this normal behaviour. Can I use this for the rest of the rules and the site? I'm using WAMP on Windows 7 Home Premium.

like image 538
jmenezes Avatar asked Dec 07 '22 07:12

jmenezes


2 Answers

You might have turned on register_globals in php.ini. Thats why you are getting variable with the name of array index (Here $_GET). It is not a best practice to turn on register_globals.

You can read more here, why register_globals is bad.

like image 91
Nauphal Avatar answered Dec 20 '22 21:12

Nauphal


In my opinion this has nothing common with .htaccess. What PHP gets is the second part of ReWrite rule, so $_GET variables should be accessible. The server gets http://www.localhost/us/2014 and the PHP gets /run/run.php?country=us&year=2014

As nauphal wrote this might be (probably is) the register_globals issue.

like image 27
Voitcus Avatar answered Dec 20 '22 21:12

Voitcus