Hướng dẫn php external function
HTML Forms (GET and POST)When a form is submitted to a PHP script, the information from that form is automatically made available to the script. There are few ways to access this information, for example: Example #1 A simple HTML form There are only two ways to access data from your HTML forms. Currently available methods are listed below: Example #2 Accessing data from a simple POST HTML form
Using a GET form is similar except you'll use the appropriate GET predefined variable instead. GET also applies to the
PHP also understands arrays in the context of form variables (see the related faq). You may, for example, group related variables together, or use this feature to retrieve values from a multiple select input. For example, let's post a form to itself and upon submission display the data: Example #3 More complex form variables
IMAGE SUBMIT variable namesWhen submitting a form, it is possible to use an image instead of the standard submit button with a tag like: When the user clicks somewhere on the image, the accompanying form will be transmitted to the server with two additional variables, sub_x and sub_y. These contain the coordinates of the user click within the image. The experienced may note that the actual variable names sent by the browser contains a period rather than an underscore, but PHP converts the period to an underscore automatically. HTTP CookiesPHP transparently supports HTTP cookies as defined by » RFC 6265. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users. You can set cookies using the setcookie() function. Cookies are part of the HTTP header, so the SetCookie function must be called before any output is sent to the browser. This is the same restriction as for the header() function. Cookie data is then available in the appropriate cookie data arrays, such as $_COOKIE as well as in $_REQUEST. See the setcookie() manual page for more details and examples.
If you wish to assign multiple values to a single cookie variable, you may assign it as an array. For example:
That will create two separate cookies although MyCookie will now be a single array in your script. If you want to set just one cookie with multiple values, consider using serialize() or explode() on the value first. Note that a cookie will replace a previous cookie by the same name in your browser unless the path or domain is different. So, for a shopping cart application you may want to keep a counter and pass this along. i.e. Example #4 A setcookie() example
Dots in incoming variable namesTypically, PHP does not alter the names of variables when they are passed into a script. However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name. For the reason, look at it:
Now, what the parser sees is a variable named $varname, followed by the string concatenation operator, followed by the barestring (i.e. unquoted string which doesn't match any known key or reserved words) 'ext'. Obviously, this doesn't have the intended result. For this reason, it is important to note that PHP will automatically replace any dots in incoming variable names with underscores. Determining variable typesBecause PHP determines the types of variables and converts them (generally) as needed, it is not always obvious what type a given variable is at any one time. PHP includes several functions which find out what type a variable is, such as: gettype(), is_array(), is_float(), is_int(), is_object(), and is_string(). See also the chapter on Types. HTTP being a text protocol, most, if not all, content that comes in Superglobal arrays, like $_POST and $_GET will remain as strings. PHP will not try to convert values to a specific type. In the example below, $_GET["var1"] will contain the string "null" and $_GET["var2"], the string "123". /index.php?var1=null&var2=123 Changelog
Anonymous ¶ 14 years ago
krydprz at iit dot edu ¶ 17 years ago
tmk-php at infeline dot org ¶ 17 years ago
Anonymous ¶ 19 years ago
lennynyktyk at yahoo dot com ¶ 18 years ago
a at b dot c dot de ¶ 20 years ago
anisgazis at gmail dot com ¶ 3 years ago
vb at bertola dot eu dot org ¶ 19 years ago
vierubino dot r3m0oFdisB1T at gmail dot com ¶ 15 years ago
fabian dot picone at gmail dot com ¶ 4 years ago
kevinrlat nospam dot ccs dot neu dot edu ¶ 19 years ago
jlratwil at yahoo dot com ¶ 17 years ago
walf ¶ 11 years ago
un shift at yahoo dot com ¶ 19 years ago
t.montg AT gmail DOT com ¶ 15 years ago
POSTer ¶ 12 years ago
carl_steinhilber at NOSPAMmentor dot com ¶ 20 years ago
Murat TASARSU ¶ 17 years ago
ch2902uk at hotmail dot com ¶ 16 years ago
jim at jamesdavis dot it ¶ 18 years ago
?>
Sadik_quake2003 at mail dot ru ¶ 5 years ago
tim at timpauly dot com ¶ 17 years ago
$arcnt > 1) // Break down passed arrays and
darren at sullivan dot net ¶ 18 years ago
keli at kmdsz dot ro ¶ 19 years ago
arjini at mac dot com ¶ 18 years ago
mattij at nitro fi no at no dot no ¶ 17 years ago
Sadik_quake2003 at mail dot ru ¶ 5 years ago
|