php - Automatic Website Login using cURL -


All I have been looking for some time that can help me.

I am writing a script that will enter Gamefly.com, and add 50 games to my line. The queue part works fairly well, but the login will not just work. I have already read about using cURL, and I have found that PHP has a decent enough time with it. So here's what I came to:

  $ ch = curl_init (); Curl_setopt ($ c, CURLOPT_URL, 'https://www.gamefly.com/member/logon/?ReturnUrl=http%3a%2f%2fwww.gamefly.com%2f'); Curl_setopt ($ CH, CURLOPT_POST, 1); Curl_setopt ($ CH, CURLOPT_POSTFIELDS, 'ctl00$ctl00$ctl00$MainContent$MainContent$MainContent$LoginForm$emailAddress=xxxx@xxxx.com&tl00 $ ctl00 $ ctl00 $ Main Containant $ Main Containant $ Main Resources $ LogForm $ Password = xxxx' ); Curl_setopt ($ CH, CURLOPT_COOKIEJAR, "cookie.txt"); $ Test = curl_exec ($ ch);  

Obviously, I think that when I do this I am getting the wrong area. Does anyone have any idea how I can login it, or am I stealing? Thank you.

Try it out:

// curl.php

  class curls {public $ cookware = ""; // Be sure to read / write cookies.txt file Public Function __ Composition ($ cookiejarfile = '/var/www/html/cookies.txt') {$ this- & gt; Cookiezer = $ cookiefile; } Function setup () {$ header = array (); $ Header [0] = "Accept: text / XML, app / XML, application / XHTML + XML,"; $ Header [0]. = "Text / html; q = 0.9; text / plain; q = 0.8; image / png; * / *; q = 0.5"; $ Header [] = "cache-control: max-age = 0"; $ Header [] = "Connection: keep-alive"; $ Header [] = "keep-alive: 300"; $ Header [] = "accept-charset: ISO-8859-1, UTF-8; Q = 0.7, *; Q = 0.7"; $ Header [] = "accept-language: en-us, n; c = 0.5"; $ Header [] = "Predama:"; // Let the browser keep it blank Curl_setopt ($ this- & gt; curl, CURLOPT_USERAGENT, 'Mozilla / 5.0 (Windows; U; Windows NT 5.2; en-US; rv: 1.8.1.7) Gecko / 20070914 Firefox / 2.0.0.7 '); Curl_setopt ($ this-> Curl, CURLOPT_HTTPHEADER, $ header); Curl_setopt ($ this-> Curl, CURLOPT_COOKIEJAR, $ this-> Cookies); Curl_setopt ($ this-> Curl, CURLOPT_COOKIEFILE, $ this-> Cookies); Curl_setopt ($ this-> Curl, CURLOPT_AUTOREFERER, true); Curl_setopt ($ this-> Curl, CURLOPT_FOLLOWLOCATION, true); Curl_setopt ($ this-> Curl, CURLOPT_RETURNTRANSFER, is true); } Find function ($ url) {$ this- & gt; Curl = curl_init ($ url); $ This- & gt; Set-up (); Return $ $-> request (); } GetAll function ($ reg, $ str) {preg_match_all ($ reg, $ str, $ matches); Returns $ matches [1]; } Festival postForm ($ url, $ fields, $ referer = '') {$ this- & gt; Curl = curl_init ($ url); $ This- & gt; Set-up (); Curl_setopt ($ this-> Curl, CURLOPT_URL, $ url); Curl_setopt ($ this-> Curl, CURLOPT_POST, 1); Curl_setopt ($ this-> Curl, CURLOPT_REFERER, $ referer); Curl_setopt ($ this- & gt; curl, CURLOPT_POSTFIELDS, $ fields); Return $ $-> request (); } Function getInfo ($ info) {$ info = ($ info == 'last')? Curl_getinfo ($ this-> Curl, CURLINFO_EFFECTIVE_URL): curl_getinfo ($ this-> Curl, $ info); Return $ info; } Function request () {return curl_exec ($ this-> curl); }}  

How to Call:

// login.php

 Include  ('/ var / www / html / Curl .php '); // This path will change to save you $ curl = new curls (); $ Url = "https://www.gamefly.com/member/logon/?ReturnUrl=http%3a%2f%2fwww.gamefly.com%2f"; $ Fields = "ctl00$ctl00$ctl00$MainContent$MainContent$MainContent$LoginForm$emailAddress=xxxx@xxxx.com&tl00 $ ctl00 $ ctl00 $ Main Resources $ Main Containant $ Main Resource $ Login Form $ Password = xxxx"; // calling url $ referrer = "http://www.gamefly.com"; $ Html = $ curl- & gt; Postform ($ url, $ field, $ referrer); $ Echo echo; // This will show you the HTML of the current page and will log in  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -