Some additional instructions on register_globals usage _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Some additional instructions on register_globals usage. Register_globals is a configuration in php. ini. this configuration affects how php receives passed parameters. if your question is: why cannot my form transmit data? Why is register_globals a configuration in php. ini that affects how php receives passed parameters? if your question is: why cannot my form transmit data? Why can't my program get the passed variables? Wait, so you need to carefully read the following content.

The value of register_globals can be set to: On or Off. let's take a piece of code to describe their differences.

 

When register_globals = Off, when receiving the next program, use $ _ GET ['User _ name'] and $ _ GET ['User _ pass'] to accept the passed values. (Note: when

When the method attribute of IS post, use $ _ POST ['User _ name'] and $ _ POST ['User _ pass']).

When register_globals = On, the next program can directly use $ user_name and $ user_pass to accept the value.

As the name implies, register_globals means registration as a global variable. Therefore, when On, the passed value will be directly registered as a global variable for use, and when Off, we need to get it in a specific array. Therefore, if you encounter the above problems that cannot get the value, you should first check whether your register_globals settings match the method you get the value. (You can use the phpinfo () function or directly view php. ini)

So why should we use Off?

Php later versions use Off by default. although you can set it to On, when you cannot control the server, the compatibility of your code becomes a major problem, you 'd better start programming with the Off style from now on.

Another question is, what should I do if I used to write a large number of scripts in the On style?

If your previous scripts are well planned, there is a public inclusion file, such as config. inc. for php files, add the following code in the file to simulate it (this code does not guarantee that 100% can solve your problem, because I did not perform a lot of tests, but I think it works well ). In addition, you can refer to the following solutions in this post:

   

Register_globals = Off not only affects how to obtainThe data transmitted by the url also affects the session and cookie. the corresponding method for obtaining the session and cookie should be: $ _ SESSION [] and $ _ COOKIE. At the same time, session processing has also changed. for example, session_register () is unnecessary and invalid. for details about the changes, see Session handling functions in php manual.

Php manual writes:

Variables provided to the script via the GET, POST, and COOKIE input mechanic, and which therefore cannot be trusted. the presence and order of variable regression Sion in this array is defined according to the PHP variables_order configuration directive.

The content in the $ _ REQUEST is actually from $ _ GET $ _ POST $ _ COOKIE. The disadvantage is that the variable cannot be determined whether it comes from get post or cookie. it is not applicable to scenarios with strict requirements.

Why? Why...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.