模拟登录

'ghhost',
        'pwd' => 'ghost123',
        'act' => 'act_login',
        'back_act'=>'http://localhost/ecshop/index.php',
    );

$data = http_build_query($data);

$fp = fsockopen("localhost",80,$errno,$errstr,5);
$request = "POST http://localhost/ecshop/user.php HTTP/1.1\r\n";
$request .= "HOST:localhost\r\n";
$request .= "Proxy-Connection:keep-alive"."\r\n";
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$request .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n";
$request .= "Referer: http://www.iphpcms.net/index.php?m=member&c=index&a=login\r\n";
$request .= "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36\r\n";
$request .= $data."\r\n";
fwrite($fp, $request);
$str = '';
while (!feof($fp)) {
    $str .= fgets($fp,1024);
}
file_put_contents("./user.html", $str);
preg_match('/ECS_ID=(.*)?;/', $str,$match);
setcookie("ECS_ID",$match[1],0,'/');
fclose($fp);
if (preg_match('/登录成功/', $str)) {
    echo "ok";
}else{
    echo "error";
}

你可能感兴趣的:(模拟登录)