No need to use $ _GET ['varName'] when using htaccess?

I just wrote an htaccess file and a simple rule.

RewriteRule ^/?([az]{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 accidentally did:

 echo $country.' '.$year; 

This gave me the result below, which is true.

 us 2014 

I did not do it:

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

But he still worked. This is normal behavior. Can I use this for the rest of the rules and site? I am using WAMP in Windows 7 Home Premium.

+4
source share
2 answers

You might have included register_globals in php.ini. This is why you get a variable with the name of the array index (here $_GET ). It is not recommended to include register_globals .

Here you can read why register_globals is bad.

+13
source

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

As nauphal wrote, this could be (possibly) a register_globals problem.

+2
source

Source: https://habr.com/ru/post/1482970/


All Articles