php - cURL follow redirects for Login form -


i'm trying use php curl login website , go specific url retrieve it's contents.

this page i'm trying view: https://dev-portal.getpebble.com/developer

however page requires user logged in, login page on: https://auth.getpebble.com/users/sign_in

the odd part login page, has hidden value "authenticity_token" must submitted form. current process is:

  1. curl content of login page. (calling curl on auth url)
  2. fetch "authenticity token" page (retrieve token post data)
  3. curl submit login page authenticity token + credentials (calling curl on auth url post data)

which works seen in image (screenshot of curl content exec): http://i.gyazo.com/4eccb78bf18f72f1da65bc9d8967541e.png

however process brings me to: https://auth.getpebble.com/me , need curl bring me https://dev-portal.getpebble.com/developer using authenticated session have. i've tried saving cookies doesn't appear work.

after step 3 above i've tried calling curl on https://dev-portal.getpebble.com/developer page keep getting redirected "localhost/users/auth/pebble" (which doesn't exist?? assume curl causing page redirect?) , if cancel redirect before occurs unauthenticated page: http://i.gyazo.com/218e00c262651017df4dcc1927def87f.png

here code create curl requests.

    private function curl($url, $postdata = false) {      $ch = curl_init($url);     curl_setopt($ch, curlopt_returntransfer, true);     curl_setopt($ch, curlopt_ssl_verifypeer, false);     curl_setopt($ch, curlopt_ssl_verifyhost, false);     curl_setopt($ch, curlopt_followlocation, true);     curl_setopt($ch, curlopt_forbid_reuse, true);     curl_setopt($ch, curlopt_fresh_connect, false);     curl_setopt($ch, curlopt_useragent, "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)");     curl_setopt($ch, curlopt_cookiefile, $this->cookie);     curl_setopt($ch, curlopt_cookiejar, $this->cookie);     curl_setopt($ch, curlopt_autoreferer, true);     if ($postdata)     {         curl_setopt($ch, curlopt_post, true);         curl_setopt($ch, curlopt_postfields, http_build_query($postdata));     }      $content = $this->content = curl_exec($ch);      echo $content;      curl_close($ch);     return $content; } 

turns out cookie being generated on different page rather https://dev-portal.getpebble.com/developer hence page create invalid session.

i managed fix using https://dev-portal.getpebble.com/users/auth/pebble instead of https://dev-portal.getpebble.com/developer , though following redirects bring me authenticated /developer page.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -