PHP demo2

<!--content
1.extract() and $_REQUEST
2.two HTTP request methods: GET and POST
3.predefined variabale
4.constant
5.operator:xor
-->
<?php
//extract($_REQUEST)
//extract() used to get the form input stored in $$_REQUEST array, it will convert the input into variables of same name as in HTML form
//The $_REQUEST superglobal array contains the information submitted to the server from the HTML form

//GET and POST method
/*some notes for GET method:
-GET method send a URL-encoded string called the query string to the server
- query string is attacjed to the end of the URL prepended with a ?, e.g /test/demo_form.asp?name1=value1&name2=value2
- requests can be cached
- requests remain in the browser history
- requests can be bookmarked
- requests should never be used when dealing with sensitive
- requests have length restrictions(query string are limited in size)
- requests should be used only to retrieve data (doing searched or handling static pages)
*/

/*some notes for POST method:
- The browser sends an encoded message body in the HTTP header to the server, not appear in the URL
- requests are never cached
- requests do not remain in the browser history
- requests cannot be bookmarked
- requests have no restrictions on data length
*/


//predefined variables
//DOCUMENT_ROOT - full path of web's document root
print $_SERVER['DOCUMENT_ROOT'];//the output is E:/wamp/www/


//constants
define('NAME','constants should be capitalized. it is case sensitive, cant start with a number');
//defined() checks whether a constant has been set, it returns TRUE if yes oherwise FALSE
if(defined('NAME')){
echo NAME."<br />";
}

//predefined/magic constant
//cant be enclosed in quptes, are not case sensitive
//enclosed in two underscores on both side
echo __LINE__."<br />";//current line number of the file
echo __FILE__."<br />";//full path and filename of the fiel
echo __FUNCTION__."<br />";//function name
echo __CLASS__."<br />";//class NAME
echo __METHOD__."<br />";//class method name


//operator
//xor, returns true, if either operand but not both are true
$x = 100;
$y = 50;

if ($x == 100 xor $y == 80) {
echo "Hello world!";
}
?>

你可能感兴趣的:(PHP demo2)