duanliao2310 2017-03-10 18:18 采纳率: 100%
浏览 27

用curl登录 - PHP

i want to write a script to log in uses curl in PHP. I wrote this code and when i try to use this script, all the time shows message: "Username or Password is incorrect", but if I give this same username and pass, I will log in.

I have no idea what this system requires more, my code now looks like:

    $curl=curl_init("http://plemiona.pl/page/auth");
    curl_setopt($curl,CURLOPT_HEADER,1);
    curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0");
    curl_setopt($curl,CURLOPT_REFERER,"http://plemiona.pl/");
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);

    curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);   
    curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,  0);

    curl_setopt($curl, CURLOPT_COOKIEFILE, "D:\cookies.txt");
    curl_setopt($curl, CURLOPT_COOKIEJAR, "D:\cookies.txt");
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded",
                                                "X-Requested-With: XMLHttpRequest",
                                                "POST /page/auth HTTP/1.1", 
                                                "Host: www.plemiona.pl",
                                                "Accept: */*",
                                                "Accept-Language: pl,en-US;q=0.7,en;q=0.3",
                                                "Content-Length: 48"));

curl_setopt($curl, CURLOPT_POST, true);
$postVars = array('username' => 'username', 
                      'password' => 'pass', 
                      'remember' => '0',);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postVars);        
    $dw=curl_exec($curl);
    echo $dw;

When i try manual log in, firefox http headers will show:

first second

My file with cookies after send POST with a curl: .plemiona.pl TRUE / FALSE 1520687485 cid 705415657

So nothing :(

It is possible that i have to use correct SSL certificate to use: curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE) ? Or what should i search to repair it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据