Delivery of variables in PHP

xiaoxiao2021-03-06  20

Sending station: Nanjing University Small Lily Station (Wed Dec 29 13:32:12 2004)

One. Form Transfer When a form is submitted to a PHP script, the information in the form will automatically be available in the script. Example: A simple HTML form

PHP code: ----------------------------------------------- ---------------------------------

name:
email:

-------------------------------------------------- ------------------------------

There are many ways to access data in the HTML form. For example: example:. Access data from a simple post html form

PHP code: ----------------------------------------------- ---------------------------------

Import_request_variables ('p', 'p _'); Print $ P_USERNAME;

// From PHP 3, you can use Print $ http_post_vars ['username'];

// If the PHP instruction register_global is available when it is ON. However, the default value is register_globals = OFF since PHP 4.2.0. // Do not advocate use / rely on this method. Print $ username;?>

-------------------------------------------------- ------------------------------

Similar to the GET form, just predefine variables with the appropriate GET. When submitting a form, you can use an image instead of the standard submission button, with a mark similar to this: When the user clicks to the image When you place, the corresponding form will be transferred to the server and add two variables SUB_X and SUB_Y. They contain the coordinates of the user click on the image. Experienced users may notice that the actual variable name sent by the browser is a point rather than underline, but PHP automatically converts points into underscores.

two. Website Passage Next You can access the GET data from $ _GET ['ID'] and $ _GET ['Name']. three. Cookie Pass 1, set cookies simple: setCookie ("MyCookie", "Value of MyCookie"; with failure time: setCookie ("WitHexPire", "Expire in 1 hour", Time () 3600); // 3600) Second = 1 hour Everything: SetCookie ("FullCookie", "Full Cookie Value", Time () 3600, "/ Forum", ".phpuser.com", 1); if you want to set multiple cookies To use arrays, the method is: setCookie ("CookieArray [0]", "Value 1"); SetCookie ("CookieArray [1]", "Value 2"); 2, receive and process cookieecho $ _COOKIE ['mycookie " ]; Echo $ _COOKIE ['cookiearray [0]']; Echo Count ($ _ cookie ['cookiearray); 3, deleting cookies To delete a ready-existing cookie, there are two ways: First, call only with Name SetCookie of the parameters, the cookie named this name will be deleted from the relational machine; another way is to set the cookie's failure time for time () or time () - 1, then this cookie is browsing this page It was deleted (it was actually invalid). It should be noted that when a cookie is deleted, its value is still valid in the current page. four. SESSION pass Test1.phpphp code: ------------------------------------------- -------------------------------------

----------------------------- -------------------------------------------------- -

TEST2.PHP

PHP code: ----------------------------------------------- ---------------------------------

-------------------------------------------------- ------------------------------

After experiment, PHP4's session only valid for the currently open browser window (at least in IE5 and NS6 under W2K). The following code can implement the SESSION's cross-window execution. TEST1.PHP

PHP code: ----------------------------------------------- ---------------------------------

--------------------------------------------------------------------------------------------- --------------------------------

Fives. The Java Script variable is passed to the PHP script. Method 1: First use the PHP to generate JS code, then pass the Java Script variable to the PHP script through the automatic refresh of the browser.

PHP code: ----------------------------------------------- ---------------------------------

/ n "; echo" Screen Height IS: ". $ _GET ['Height']."

Echo "