ruskiem Posted January 27, 2014 Share Posted January 27, 2014 Hi, Im using a web gateway for a D&D game, and I want to access it via curl to automate one really time-eating activity, like clicking every x minutes for me. And got stuck at that point, when the game's gateway does not sees curl to actually be logged after curl sent the login data, cookies are on, but gateway seems to not leting me in. im using crul from few years to login to many things, i think im doing it right, but somehow it does not works, please, can somebody tell me why it does not work, i do everything how it should be done ?This is main code: <?php require_once '_shoelace.php'; require_once ROOT . '_include/class.curl.php'; set_time_limit('400'); $h = array( 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0', 'Cache-Control: no-cache', 'Connection: keep-alive', 'Content-Encoding: gzip', 'Content-Type: text/xml; charset=UTF-8', 'Transfer-Encoding: chunked', 'Vary: Accept-encoding' ); $url = 'https://gateway.playneverwinter.com'; $url = 'http://gateway.playneverwinter.com/#char%28mychar@mylogin%29/'; echo '<base href="https://gateway.playneverwinter.com/#/characterselect">'; $c = new Curl($url); $x = $c->httpheader($h)->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->post('user=mylogin%40o2.pl&pw=mypass')->exec(); // $x = '{"result":"user_login_ok","destURL":"http://gateway.playneverwinter.com/","idBrowser":"HqZ7PdKTmZc2rjQYiAac4sI3ZokJfyCtpCxCKzIgB","idTicket":1764876376,"idAccount":9820944}'; $x = json_decode($x); if ($x) { $url = "http://gateway.playneverwinter.com/?account={$x->idAccount}&ticket={$x->idTicket}&browser={$x->idBrowser}"; $c = new Curl($url); $x = $c->httpheader($h)->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $url = 'http://gateway.playneverwinter.com/lang.js?cb=18d2f832bed403993f7d6ae7021a0ebepl'; $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $url = 'http://gateway.playneverwinter.com/socket.io/1/?t=' . date('U');; $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $t = explode(':', $x); $url = 'http://gateway.playneverwinter.com/socket.io/1/xhr-polling/' . $t[0] . '?t=' . date('U'); $c = new Curl($url); // $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->post('5:::{"name":"Client_OneTimeCode","args":[{"code":"36809","name":"Maa Brawser"}]}')->exec(); // krumo($x); $url = 'http://gateway.playneverwinter.com/socket.io/1/xhr-polling/' . $t[0] . '?t=' . date('U'); $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); krumo($x); $url = 'http://gateway.playneverwinter.com/socket.io/1/xhr-polling/' . $t[0] . '?t=' . date('U'); $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); krumo($x); $url = 'http://gateway.playneverwinter.com/socket.io/1/xhr-polling/' . $t[0] . '?t=' . date('U'); $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); krumo($x); } die(); $url = 'http://gateway.playneverwinter.com/time'; $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $url = 'http://gateway.playneverwinter.com/dataTables.js'; $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); krumo($x); $url = 'http://gateway.playneverwinter.com/socket.io/1/?t=1390649083641'; $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $t = explode(':', $x); $url = 'http://gateway.playneverwinter.com/socket.io/1/xhr-polling/' . $t[0] . '?t=1390657023475'; $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); $url = 'http://gateway.playneverwinter.com/socket.io/1/xhr-polling/' . $t[0] . '?t=' . date('U'); $c = new Curl($url); $x = $c->ssl(3)->cookies($_C['cookie_dir'] . 'nw.txt')->exec(); krumo($x); ?> And this is my overlay for curl: <?php Class Curl { public $_header = FALSE; public $_nobody = FALSE; public $dir; public $cache = FALSE; public $cache_time = FALSE; public $cache_gzip = TRUE; function __construct($url = null) { global $_C; if (!function_exists('curl_init')) { trigger_error('PHP was not built with --with-curl, rebuild PHP to use the curl class.', E_USER_ERROR) ; }else{ $this->agent = "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1"; $this->agent = "Mozilla/5.0 (Windows NT 6.0; rv:22.0) Gecko/20100101 Firefox/22.0"; $this->ch = curl_init(); $this->url = $url; curl_setopt($this->ch, CURLOPT_URL, $this->url); curl_setopt($this->ch, CURLOPT_USERAGENT, $this->agent); curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: 89.37.54.44", "HTTP_X_FORWARDED_FOR: 89.37.54.44")); } } function proxy($proxy) { curl_setopt($this->ch, CURLOPT_PROXY, $proxy); //182.253.72.161 81 return $this; } function cache_file($u) { if (isset($this->file) && $this->file) $u = $this->file; $u = str_replace(array('http://', '/', '.', '?', '&', ',', 'html'), '', $u); return $u; } function cache($c = 3600, $file = NULL) { global $_C; if ($c && !is_numeric($c) && !$file) { $file = $c; $c = 3600; } if (isset($_C['cachedir'])) $this->dir = $_C['cachedir'] . '_curl/'; elseif (defined('ROOT')) $this->dir = ROOT . "_assets/_cache/_curl/"; if (file_exists($this->dir)) { $this->cache = TRUE; if ($file) $this->cache = $file; $this->cache_time = $c; } return $this; } function ssl($ver = FALSE) { curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE); if ($ver) { curl_setopt($this->ch, CURLOPT_SSLVERSION, $ver); } return $this; } function httpheader($h) { curl_setopt($this->ch, CURLOPT_HTTPHEADER, $h); return $this; } function post($p) { curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_POSTFIELDS, $p); return $this; } function cookies($c) { curl_setopt($this->ch, CURLOPT_COOKIEFILE, $c); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $c); return $this; } function referer($u = null) { return $this->ref($u); } function ref($url = null) { if (!$url) $url = $this->url; curl_setopt($this->ch, CURLOPT_REFERER, $url); return $this; } function file($f) { curl_setopt($this->ch, CURLOPT_FILE, $f); return $this; } function get($d) { if (is_array($d)) { $t = ""; foreach ($d as $c=>$v) { if ($t) $t .= "&"; $t .= $c . "=" . $v; } }else $t = $d; curl_setopt($this->ch, CURLOPT_URL, $this->url . '?' . $t); return $this; } function header($h = 1) { curl_setopt($this->ch, CURLOPT_HEADER, $h); if ($h) $this->_header = TRUE; return $this; } function nobody($nb = 1) { curl_setopt($this->ch, CURLOPT_NOBODY, $nb); if ($nb) $this->_nobody = TRUE; return $this; } function exec() { if ($this->cache) { if ($this->cache !== TRUE) $file = $this->cache; else $file = md5($this->url); $a = glob($this->dir . $file . '~*'); foreach ($a as $_a) { list($f, $exp) = explode('~', $_a); if ($exp > date('U')) { $x = file_get_contents($this->dir . $file . '~' . $exp); if ($this->cache_gzip) { $x = gzinflate($x); } return $x; } } } $x = curl_exec($this->ch); $_x = $x; if(curl_exec($this->ch) === false) { echo 'Curl error: ' . curl_error($this->ch); } $this->close(); if ($this->cache && $x) { if ($this->cache !== TRUE) $file = $this->cache; else $file = md5($this->url); $end = (date('U') * 1) + $this->cache_time; $file .= '~' . $end; if ($this->cache_gzip) { $x = gzdeflate($x, 2); } file_put_contents($this->dir . DS . $file, $x); unset($x); // die(); } return $_x; } function close() { curl_close($this->ch); } function info() { return curl_getinfo($this->ch); } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.