破釜沉舟论坛 » WEB 开发 » php script

2007-11-6 16:37 php店小二
php script

[code]<?php
$host = "127.0.0.1";
$port = "80";
$fp = fsockopen("{$host}", $port, $errno, $errstr, 30);
if(!$fp)
{
        echo "$errstr ($errno)<br/>\n";
}
else
{
        $param = "op=check_ad_passwd&user_name=songxinfeng&user_pass=".urlencode('$AbcD1234');
        $out = "POST /ad/soap/ad_bridge.php HTTP/1.1\r\nHost: {$host}\r\nReferer: \r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ".strlen($param)."\r\nConnection: Close\r\n\r\n".$param;
        $inheader = 1;
        $get_info = "";
        fwrite($fp, $out);
        while (!feof($fp))
        {
                $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据
                if ($inheader && ($line == "\n" || $line == "\r\n"))
                {
                        $inheader = 0;
                }
                if ($inheader == 0)
                {
                        $get_info .= $line;
                }
        }
        fclose($fp);
        echo "<pre>";
        $re =json_decode($get_info);
        print_r($re->username);
}
?>[/code]

此脚本为 fsocketopen模拟post数据

2008-3-3 01:09 木舟
如果加载了curl模块 用curl 更简单些.

页: [1]
查看完整版本: php script


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.