PHP inventory 2

Source: Internet
Author: User
1 single and double quotation marks
<? PHP
$ Var = 12345;
Echo $ var; // print the value of $ var variable 12345
Echo '$ var'; // print the string '$ var'
Echo "$ Var"; // print the value of $ var variable 12345
?>
No matter what is in single quotes, it is printed as is

2 header Functions
Header ("Location: http://www.baidu.com ");
Headers ("Refresh: 3; url = http://www.baidu.com ");
3 HTTP Verification
<? PHP
$ Username = 'username ';
$ Password = 'Password ';
If (! Isset ($ php_auth_user )){
Header ("www-Authenticate: Basic realm = \" php login verification \"");
Header ("HTTP/1.0 401 unauthorized ");
Echo "Operation aborted \ n ";
Exit;
} Else {
If ($ php_auth_user = $ userame) & ($ php_auth_pw = $ password )){
Print ("You have logged on successfully <br/> ");
} Else {
Print ("Logon Failed <br/> ");
}
}
?>
4 curl
Curl is the abbreviation of client URL library functions and is mainly used for network use. In PhP5, you can open extension = php_curl.dll.
Example:
<? PHP
// Initialize curl
$ CH = curl_init () or die (curl_error ());
// Set URL parameters
Curl_setopt ($ ch, curlopt_url, "http://www.baidu.com/s? WD = PhP5 ");
// Request that curl return data
Curl_setopt ($ ch, curlopt_returntransfer, 1 );
// Execute the request
$ Result = curl_exec ($ ch) or die (curl_error ());
// Obtain the returned result and display it
Echo $ result;
Echo curl_error ($ ch );
// Disable curl
Curl_close ($ ch );
?>
Download remote files
<? PHP
Function curl_download ($ remote, $ local ){
$ CP = curl_init ($ remote );
$ Fp = fopen ($ local, "W ");

Curl_setopt ($ CP, curlopt_file, $ FP );
Curl_setopt ($ CP, curlopt_header, 0 );

Curl_exec ($ CP );
Curl_close ($ CP );
Fclose ($ FP );
}
// Obtain the file from the remote end and save it in the Directory D: \ Software on the local hard disk.
Curl_download ("http://www.skycn.com/downloads/file.zip", "d:/software ");
?>
4. Use the snoopy class
The Snoopy class is an item tree on sourceforge.net and can be easily captured.
<? PHP
Include "Snoopy. Class. php ";
$ Snoopy = new Snoopy;
$ Snoopy-> fetch ("http://bbs.sina.com.cn/index.html ");
$ Line = $ Snoopy-> results;
Print_r ($ line );
?>
Automatic Login
<? PHP
Include_once "Snoopy. Class. php ";
$ Snoopy = new Snoopy;
// The URL you want to submit
$ Submit_url = "http://www.example.org/login/logging.php? Action = login ";
// Some text box parameters in the form
$ Submit_vars ["loginmode"] = "normal ";
$ Submit_vars ["styleid"] = "1 ";
$ Submit_vars ["username"] = "Administrator"; // your Username
$ Submit_vars ["password"] = "12345"; // your password
$ Submit_vars ["loginsubmit"] = "& nbsp; ";
$ Snoopy-> submit ($ submit_url, $ submit_vars );
Print $ Snoopy-> results;
?>

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.