PHP simulation post submission 2 ways to explain _php skills

Source: Internet
Author: User

One, through the Curl function

Copy Code code as follows:

$post _data = Array ();
$post _data[' clientname '] = "test08";
$post _data[' clientpasswd '] = "test08";
$post _data[' submit '] = "submit";
$url = ' http://xxx.xxx.xxx.xx/xx/xxx/top.php ';
$o = "";
foreach ($post _data as $k => $v)
{
$o. = "$k =". UrlEncode ($v). & ";
}
$post _data=substr ($o, 0,-1);
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_url, $url);
To support cookies
curl_setopt ($ch, Curlopt_cookiejar, ' cookie.txt ');
curl_setopt ($ch, Curlopt_postfields, $post _data);
$result = curl_exec ($ch);

ii. Adoption of Fsockopen
Copy Code code as follows:

$URL = ' http://xxx.xxx.xxx.xx/xx/xxx/top.php ';
$post _data[' clientname '] = "test08";
$post _data[' clientpasswd '] = "test08";
$post _data[' submit '] = "ログイン";
$referrer = "";
Parsing the given URL
$URL _info=parse_url ($URL);
Building referrer
if ($referrer = = "")//if not given use this script as referrer
$referrer =<pre class=php name= "code" >{1}</PRE><BR>
server["Script_uri"]; Making string from $dataforeach ($post _data as $key => $value) $values []= "$key =". UrlEncode ($value); $data _string=implode ("&", $values)//Find out which the port is needed-if to given use standard (=80) if (!isset ($URL _inf o["Port"]) $URL _info["Port"]=80;//
Building post-request: $request. = "POST". $URL _info["path"]. " Http/1.1\n "$request. =" Host: ". $URL _info[" host "]." \ n "; $request. =" Referer: $referrer \ n "; $request. =" content-type:application/x-www-form-urlencoded\n "; $request. =" Content-length: ". strlen ($data _string)." \ n "; $request. =" Connection:
Close\n "$request. =" \ n "; $request. = $data _string." \ n "; $fp = Fsockopen ($URL _info[" host "], $URL _info[" Port "), Fputs ($fp, $request), while (!feof ($fp)) {$result. = fgets ($ FP, 128);} Fclose ($FP);
<PRE></PRE>
<P><BR>
</P>
<p>snoopy Class (2) <BR>
Sourceforge.net/projects/snoopy/</p>
<P>http://www.redalt.com/xref/trunk/nav.htm?wp-includes/class-snoopy.php.htm</P>
<p>http Class (1,2) </P>
<P>http://www.phpclasses.org/browse/download/1/file/5/name/http.php</P>
<p>pear http_request</p>
<P>http://pear.php.net/package/HTTP_Request</P>
<p class=akpc_pop>popularity:70%</p>
<P> </P>

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.