当前位置:Gxlcms > PHP教程 > javascript-php如何模拟登录http://www.19lou.com/login,curl无法登陆成功

javascript-php如何模拟登录http://www.19lou.com/login,curl无法登陆成功

时间:2021-07-01 10:21:17 帮助过:3人阅读

求大神给个php示例代码模拟登录http://www.19lou.com/login
我用curl试了无法登陆成功。
账号给大家注册好了

谢谢。

回复内容:

求大神给个php示例代码模拟登录http://www.19lou.com/login
我用curl试了无法登陆成功。
账号给大家注册好了

谢谢。


简单测试了一下,没有特殊的校验啊,传这些参数就好了,refererUrl这个参数可以从


这个链接的r=处找到

================分割线======================
贴代码吧

function curl_post_contents($url, $params, $cookie_file, $has_cookie, $use_http_build_query = false, $headers = array(), $time_out = 30)
{
    if ($use_http_build_query) {
        $params = http_build_query($params);
    }

    $curlHandle = curl_init();
    if ($headers) {
        curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $headers);
    }
    curl_setopt($curlHandle, CURLOPT_POST, 1);
    curl_setopt($curlHandle, CURLOPT_URL, $url);
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, 0); //让CURL支持HTTPS访问
    curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, $time_out);
    curl_setopt($curlHandle, CURLOPT_TIMEOUT, $time_out);
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $params);
    curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, 1);//跳转到重定向的地址
    if ($has_cookie)
        curl_setopt($curlHandle, CURLOPT_COOKIEFILE, $cookie_file);
    else
        curl_setopt($curlHandle, CURLOPT_COOKIEJAR, $cookie_file);
    $result = curl_exec($curlHandle);

    curl_close($curlHandle);
    return $result;
}



$data = array(
    'refererUrl'=>'aHR0cDovL3d3dy4xOWxvdS5jb20=',
    'checked' => 0,
    'userName' => 'wangtets123',
    'userPass' => '#1234567890',
    'ssl' => true
);
$url = 'https://www.19lou.com/login';
$cookie_file = dirname(__FILE__)."/pic.cookie";
$result = curl_post_contents($url,$data,$cookie_file,false,true);
echo $result;

cookie放在pic.cookie里面,接下来要做什么把这个cookie放进去就好了

谢谢大家。已经解决
代码如下

'aHR0cDovL3d3dy4xOWxvdS5jb20v',
   'checked'=>'0',
   'userName'=>$user,
   'userPass'=>$pass,
    'captcha'=>'',
    'remember'=>'1',
    'ssl'=>'true', 
); 
$url = "https://www.19lou.com/login";
$cookie = dirname(__FILE__) . '/sss.txt'; 
//登录后要获取信息的地址 
$url1 = "http://www.19lou.com/wap/myinfo/index"; 
//模拟登录 
login_post($url, $cookie, $post); 
//获取登录页的信息 
echo $content = get_content($url1, $cookie); 

不知道php的curl会不会在302重定向的时候,丢失cookie, 刚刚看了看,在login之后是302重定向了

在python的urllib2遇到302时候,默认设置会丢失cookie,所以个人感觉如果你提交的参数没有问题的话, 可能是这个原因。

你想要的curl,bash版本:

curl 'https://www.19lou.com/login' -H 'Pragma: no-cache' -H 'Origin: http://www.19lou.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: http://www.19lou.com/login' -H 'Cookie: JSESSIONID=1F755C103A98DD613F80F3AFB99B3EC9; sys=67174666.20480.0000; _DM_SID_=b13ac27ac3d29a85ad6094b375981b8f; _DM_S_=487781a528838b00e091f3d500a33239' -H 'Connection: keep-alive' -H 'DNT: 1' --data 'refererUrl=aHR0cDovL3d3dy4xOWxvdS5jb20%3D&checked=0&userName=wangtets123&userPass=%231234567890&captcha=&remember=1&ssl=true' --compressed

善用chrome的F12,很强大的。

逐步分析 就行

人家做了防跨站访问的话就不能实现了

人气教程排行