Outside PHP variable _php tutorial

Source: Internet
Author: User
HTML forms (Get and post)
When a form is submitted to a PHP script, the variables obtained from the form are automatically set to be available by the PHP script. Please refer to the following example:
 
Example 5-2. Simple form variable (easy form variable)

When committed, PHP will create a variable "$name" that will contain any content entered in the form in "name".
PHP also knows how to schedule the context of a form variable, but only once. You can, for example, describe a set of variables at the same time, or use this feature to re-derive values from multiple selection inputs:
 
Example 5-3. More complex form variables

If PHP's Track_var feature is turned on, any of its structure settings or Instructions, and then a variable submission via POST or GET mode will find it appropriate to use the Global Union array "$HTTP _post_vars" and "$HTTP _get_vars".
Graph commit Variable Name
When submitting a form, it is possible to use an image instead of the standard Tagged submit button, for example:

When the user clicks anywhere on the image, the corresponding form is routed to the server using two additional variables (sub_x and sub_y). They contain information about where the user clicked the corresponding location on the graph. This will include the name of the real variable from the browser (even the underscore), but PHP will automatically convert it to an underlined form.
HTTP Cookies
PHP certainly supports the use of HTTP Cookies defined by Netscapes spec. Cookies are devices that store data on a remote browser and are used to track and authenticate a user's identity. You can use the Setcookie () function to set up cookies. Cookies are part of the HTTP header, so the Setcookie program must be called before it is exported to the browser. This is similar to the header () function setting. Any cookies sent from the server to the user will automatically be converted into a PHP variable, just like data in get and post patterns.
If you want to assign multiple values to a single cookie, simply add a "[]" after the name of the cookie. For example:
Setcookie ("mycookie[]", "testing", Time () +3600);
Note that if the domain or path is not the same on your browser, the cookie will replace the previous cookie with the same name. So, for a shopping order application, you might want to keep a counter that transmits it through a cookie at the same time, for example:
 
Example 5-4. Setcookie Example (example of setting cookies)
$Count + +;
Setcookie ("Count", $Count, Time () +3600);
Setcookie ("cart[$Count]", $item, Time () +3600);
 
Environment variables
PHP automatically uses environment variables as common PHP variables, as shown in the following example.
Echo $HOME; /* Shows the HOME environment variable, if set. */
Since the information is passed in with mechanisms such as Get,post,cookie, and the PHP variable is automatically created, it is sometimes best to read a variable from the outside environment to make sure you are using the correct version. The getenv () function is the job, and you can use the putenv () function to set an environment variable.

http://www.bkjia.com/PHPjc/531945.html www.bkjia.com true http://www.bkjia.com/PHPjc/531945.html techarticle HTML forms (get and post) when a form is submitted to a PHP script, the variables obtained from the form are automatically set to be available by the PHP script. Please refer to the following example: Example 5-2. Simple ...

  • 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.