This article mainly introduces the php method for simulating post data submission. The example analyzes the socket method for simulating post data submission, which has some reference value. For more information, see
This article mainly introduces the php method for simulating post data submission. The example analyzes the socket method for simulating post data submission, which has some reference value. For more information, see
This example describes how to simulate post data submission in php. Share it with you for your reference. The details are as follows:
Php simulates post submission of data, which is of great use and can be used for website collection and login.
Here, the Forum logon in my project is used as an example to describe:
The Code is as follows:
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 )){
$ 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 );
}
I hope this article will help you with php programming.
,