Php simulate post to submit data _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags bbpress
Php simulates post to submit data. Php simulates post submission of data, which is very useful. it can be used for website Collection, login, and so on. taking the Forum logon in my project as an example functionA_bbslogin ($ user_login, $ password, $ host, $ port80) {php is required to simulate post submission of data, which is of great use and can be used for website Collection and login.

// Take the Forum logon in my project as an example
Function A_bbslogin ($ user_login, $ password, $ host, $ port = "80 "){
// The post data to be submitted
$ Argv = array (
'Cookies' => array ('User _ login' => $ user_login, 'password' => $ password, '_ wp_http_referer' => '/bbpress /', 're' => '', 'Remember '=> true)
);
Foreach ($ argv ['cookies'] as $ key => $ value ){
$ Params [] = $ key. '='. $ value;
}
$ Params = implode ('&', $ params );
$ Header = "POST/bbpress/bb-login.php HTTP/1.1 \ r \ n ";
$ Header. = "Host: $ host: $ port \ r \ n ";
$ Header. = "Content-Type: application/x-www-form-urlencoded \ r \ n ";
$ Header. = "Content-Length:". strlen ($ params). "\ r \ n ";
$ Header. = "Connection: Close \ r \ n ";
$ Header. = $ params;
$ Fp = fsockopen ($ host, $ port );
Fputs ($ fp, $ header );
While (! Feof ($ fp) {// LieHuo29.Net
$ Str = fgets ($ fp); // The following is your own logic code. here we simulate cookies for synchronous login.
If (! (Strpos ($ str, "Set-Cookie:") === false )){
$ Tmparray = explode ("", $ str );
$ Cookiearray = explode ("=", $ tmparray [1]);
$ Cookiepaths = explode ("=", $ tmparray [6]);
$ Cookiename = urldecode ($ cookiearray [0]);
$ Cookievalue = urldecode (substr ($ cookiearray [1], 0, strlen ($ cookiearray [1])-1 ));
$ Cookietime = time () + 3600*24*7;
$ Cookiepath = urldecode (substr ($ cookiepaths [1], 0, strlen ($ cookiepaths [1])-1 ));
Setcookie ($ cookiename, $ cookievalue, $ cookietime, $ cookiepath );
}
}
Fclose ($ fp );
}

Address: http://www.52blogger.com/archives/595

Login // take the forum login in my project as an example function A_bbslogin ($ user_login, $ password, $ host, $ port = 80) {// Yes...

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.