dtnnpt11795 2018-07-28 09:36
浏览 37
已采纳

如何通过php curl登录这个网站?

I'm trying to log in here that http://www.wemakeprice.com/ by curl, but i don't know what where send data for login and where i get receve to login cookie

some site is easy because can see where send to login form data by network tap in Developer Tools

but that site is cen't find where i send data for login.

i'm looking for Helpful document about this Problem

can you give me advice?

Thanks for look.

  • 写回答

1条回答 默认 最新

  • dongli8466 2018-07-28 10:55
    关注

    Try this snippet I wrote, replace username and password with your corresponding credentials, and replace the URL with the page you want to grab data from (a page that requires a login).

    Check the post data that is sent in browser inspector. Replace $postinfo with the correct post data to ensure you are sending the right data. "email" and "Password" as the $postdata might not work for the site you are trying to login into. If you have trouble, post the inspector's data that is reported in the network tab and I'll try and help.

        $username = "email@example.com";
        $password = "MyPassword123";
    
        $dir = $_SERVER['DOCUMENT_ROOT']."/ctemp";
    
        $path = tempnam(sys_get_temp_dir(), 'MyTempCookie');
    
        $url = "https://www.example.com/dashboard/";
        $postinfo = "email=".$username."&Password=".$password;
    
        $cookie_file_path = $path."/cookie.txt";
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_NOBODY, false);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        //for certain features, set the cookie the site has - this is optional
        curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
        curl_setopt($ch, CURLOPT_USERAGENT,
            "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
        curl_exec($ch);
    
        curl_setopt($ch, CURLOPT_URL, $url);
        $html_data = curl_exec($ch);
        curl_close($ch);
        echo $html_data;
    

    Here at the end I'm simply just echoing the return html data. But you can do whatever you want with it and search for the data inside the response that you need.

    Edit: Just saw that the site has a recaptcha for their login process. Logging in via cURL is going to be far more complex now since they present the recaptcha code to you in an image. Might want to look into tutorials on spoofing recaptcha data. Good luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 潜在扩散模型的Unet特征提取