<?php
error_reporting( E_ALL );
$fp = null;
function step1( $host, $method, $jsession="" )

global $fp;
if ($fp==null) {
$fp = fsockopen($host, 80, $errno, $errstr ) or exit( $errstr . "--->" . $errno );
}    $header = "$method\r\n"; 
$header .= "Accept: */*\r\n";
$header .= "Accept-Language: zh-cn\r\n";
$header .= "Accept-Encoding: gzip, deflate\r\n";
$header .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)\r\n";
    $header .= "Host: $host\r\n"; 
$header .= "Connection: Keep-Alive\r\n
\r\n";
//echo $header."---------";
$result = fputs( $fp, $header );
//var_dump($result);
    $response="";
    while(!feof($fp)) 
    { 
        $response .= fgets($fp); 
    }

/*if ( preg_match('/JSESSIONID=/i', $response, $matches))
return $matches;*/
if ( preg_match( '/ggcx.jsp\?([0-9]*=[0-9]*)\"/i', $response, $matches ) )
return $matches[1];
//var_dump($response);
}
$host="www.miibeian.gov.cn";
$method="GET /chaxun/ggcx.jsp HTTP/1.1";
$random = step1($host, $method);
echo $random;
$method="GET /chaxun/ggcx.jsp?$random HTTP/1.1";
$random = step1($host, $method, 1);
echo $random;
?>
用户查询域名时,由地址
http://www.miibeian.gov.cn/chaxun/ggcx.jsp
跳转
http://www.miibeian.gov.cn/chaxun/ggcx.jsp?2926976919=3380692313
这里设置的cookie,如下图:2 小时前
现在想取得jsessionid,但在第二次通过模拟发包后,fgets返回false。
请高手指教,谢谢!

解决方案 »

  1.   

    $response .= fgets($fp); 
    应该是去读取
    $response .= fgets($result); 吧
      

  2.   

    fputs是fwrite的别名函数
    fwrite -- 写入文件(可安全用于二进制文件)
    说明
    int fwrite ( resource handle, string string [, int length] )
    fwrite() 把 string 的内容写入 文件指针 handle 处。 如果指定了 length,当写入了 length 个字节或者写完了 string 以后,写入就会停止,视乎先碰到哪种情况。 fwrite() 返回写入的字符数,出现错误时则返回 FALSE 。
      

  3.   

    1 要取出 随机数.
    2 要取出 COOKIE下次 请求的时候. 附上随机数及COOKIE.. 主要是你下次没有附上COOKIE数据
      

  4.   

    用户查询域名时,由地址 
    http://www.miibeian.gov.cn/chaxun/ggcx.jsp 
    跳转 
    http://www.miibeian.gov.cn/chaxun/ggcx.jsp?2926976919=3380692313 
    这里设置的cookie
    我是第一次模拟请求http://www.miibeian.gov.cn/chaxun/ggcx.jsp
    然后得到随机数,再请求带有随机数的地址,希望取得cookie,可是根本就无法取得,没有任何返回