URL Parameters to PHP Variables

自作多情 提交于 2019-12-12 02:32:15

问题


I've been doing PHP for a while now, never needed assistance, but totally confused this time. I have a single line of code with one echo statement.

Problem: URL parameters are automatically assuming PHP variable values of the same name. For example, I have a URL with a parameter named 'var_name' like this:

http://www.example.com?var_name=abc123

and a 1-line PHP script with a variable named 'var_name', like this:

echo $var_name;

then I get output on the page of: abc123

This is the only code in the PHP page! This behavior is exactly how I expect $_GET to work, but I'm not using it.

I am having this problem only on 1 specific server, which is running PHP 5.2. I have tested on 4 other servers, none have this behavior. I assume it's a PHP config issue, but running default config and can't find anything in config documention. Please help.

Thanks in advance. Matt-


回答1:


This is called register globals. If a server has register globals turned on, then you can do this.

I would recommend not to have register globals on any server. Since it can introduce a security flaw in your system.

An example of a security flaw with this.

if($auth == true)
{
    // sensitive stuff here
}

If auth is just a regular variable, then I can do this in the URL.

http://www.example.com/page.php?auth=true

And see the sensitive information.




回答2:


You probably have register_globals enabled:

See the manual for info.



来源:https://stackoverflow.com/questions/4221136/url-parameters-to-php-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!