dtbc37573 2018-08-09 15:31
浏览 22

如何使用PHP curl命令登录网站

I'm trying to login to this site using PHP curl commands:

https://users.premierleague.com/accounts/login/

So far my code looks like this

`

  $ch = curl_init(); 

  curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_URL => 'https://users.premierleague.com/accounts/login/',
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => array(
      'login' => 'username',
      'password' => 'password',
      'app' => 'plfpl-web',
      'redirect_uri' => 'https://fantasy.premierleague.com/a/login'
    ),
    CURLOPT_FOLLOWLOCATION => TRUE,
    CURLOPT_COOKIESESSION => TRUE,
    CURLOPT_COOKIEFILE => $cookie_file_path,
    CURLOPT_COOKIEJAR => $cookie_file_path
  ));

  $output = curl_exec($ch);
  curl_close($ch);

`

When I run this in a browser though it doesn't login. I get a new cookie file in $cookie_file_path but no successful login. It just takes prints out the login page html. I've tried analysing things using the networks tab in chrome developer tools, but am none the wiser. I'm guessing it has something to do with a session cookie. Any help much appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)