- PHP code
<?php $domain = "user.baidu.net"; $port = 80; $uri = "/reg.php?cont=store_user"; $refe = "http://user.baidu.net/reg.php"; $num=1; //data中的变量num ,如果想要取变量1---100 怎么写 $data ="lang=Chinese&username=popo{$num}&password1=123456&password2=123456&mobile=&email=&srvid=1&textarea=%E6%8F%90%E7%A4%BA%EF%BC%9A%E8%AF%B7%E4%BB%94%E7%BB%86%E9%98%85%E8%AF%BB%E4%BB%A5%E4%B8%8B%E6%9D%A1%E6%AC%BE%EF%BC%8C%E5%86%8D%E6%B3%A8%E5%86%8C%E5%B8%90%E5%8F%B7%E3%80%82%E4%BD%BF%E7%94%A8%E6%9C%AC%E7%BD%91%E7%AB%99%E8%A1%A8%E7%A4%BA%E6%82%A8%E5%90%8C%E6%84%8F%E9%81%B5%E5%AE%88%E8%BF%99%E4%BA%9B%E6%9D%A1%E6%AC%BE%E5%92%8C%E6%9D%A1%E4%BB%B6%E3%80%82%E5%A6%82%E6%9E%9C%E6%82%A8%E4%B8%8D%E6%8E%A5%E5%8F%97%E8%BF%99%E4%BA%9B%E6%9D%A1%E6%AC%BE%EF%BC%88%E2%80%9C%E6%9D%A1%E6%AC%BE%E2%80%9D%EF%BC%89%EF%BC%8C%E8%AF%B7%E5%8B%BF%E6%B3%A8%E5%86%8C%E3%80%82&acceptterms=1&adduser=%E5%88%9B%E5%BB%BA%E8%B4%A6%E6%88%B7"; $protocolstr = "POST {$uri} HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\nReferer: {$refe}\r\nAccept-Language: zh-cn\nContent-Type:application/x-www-form-urlencoded\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; 360SE)\nHost: {$domain}\nContent-Length: 702\nConnection: Keep-Alive\nCache-Control: no-cache\nCookie: login_user=aabbcc02; PHPSESSID=hs23i9tguang96k7del3oafc64; lzstat_uv=2113815751356026816|2652038; lzstat_ss=2265145365_0_1335089150_2652038\n\n{$data}"; for ($i=1;$i<10;$i++){ //这里循环 赋值不起作用 $num=$i; $sock = fsockopen($domain, $port, $errno, $errstr, 30); if (!$sock) die("$errstr ($errno)\n"); fputs($sock, $protocolstr); fgets($sock, 4096); echo $num." "; } fclose($sock); ?>
------解决方案--------------------
- PHP code
<?php for ($i=1;$i<10;$i++){ $num=$i; $data="lang=Chinese&username=popo{$num}&password1=123456&password2=123456&mobile=&email=&srvid=1&textarea=%E6%8F%90%E7%A4%BA%EF%BC%9A%E8%AF%B7%E4%BB%94%E7%BB%86%E9%98%85%E8%AF%BB%E4%BB%A5%E4%B8%8B%E6%9D%A1%E6%AC%BE%EF%BC%8C%E5%86%8D%E6%B3%A8%E5%86%8C%E5%B8%90%E5%8F%B7%E3%80%82%E4%BD%BF%E7%94%A8%E6%9C%AC%E7%BD%91%E7%AB%99%E8%A1%A8%E7%A4%BA%E6%82%A8%E5%90%8C%E6%84%8F%E9%81%B5%E5%AE%88%E8%BF%99%E4%BA%9B%E6%9D%A1%E6%AC%BE%E5%92%8C%E6%9D%A1%E4%BB%B6%E3%80%82%E5%A6%82%E6%9E%9C%E6%82%A8%E4%B8%8D%E6%8E%A5%E5%8F%97%E8%BF%99%E4%BA%9B%E6%9D%A1%E6%AC%BE%EF%BC%88%E2%80%9C%E6%9D%A1%E6%AC%BE%E2%80%9D%EF%BC%89%EF%BC%8C%E8%AF%B7%E5%8B%BF%E6%B3%A8%E5%86%8C%E3%80%82&acceptterms=1&adduser=%E5%88%9B%E5%BB%BA%E8%B4%A6%E6%88%B7"; $protocolstr = "POST {$uri} HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\nReferer: {$refe}\r\nAccept-Language: zh-cn\nContent-Type:application/x-www-form-urlencoded\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; 360SE)\nHost: {$domain}\nContent-Length: 702\nConnection: Keep-Alive\nCache-Control: no-cache\nCookie: login_user=aabbcc02; PHPSESSID=hs23i9tguang96k7del3oafc64; lzstat_uv=2113815751356026816|2652038; lzstat_ss=2265145365_0_1335089150_2652038\n\n{$data}"; $sock = fsockopen($domain, $port, $errno, $errstr, 30); //.... }