1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| session_start();
///////////////////////////////////////////////
// Curl Get
///////////////////////////////////////////////
function curl_get($url, $cookiefile, $referer = "") {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, $referer);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
///////////////////////////////////////////////
// Curl Post
///////////////////////////////////////////////
function curl_post($url, $cookiefile, $post, $referer = "") {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, $referer);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
///////////////////////////////////////////////
// Neopets Login
///////////////////////////////////////////////
function neopets_login($username, $password, $cookiefile) {
$arrayPost = array();
$arrayPost["username"] = $username;
$arrayPost["password"] = $password;
$arrayPost["destination"] = "/index.phtml";
$url = "http://www.neopets.com/login.phtml";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $arrayPost);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
///////////////////////////////////////////////
// Connexion à Neopets
///////////////////////////////////////////////
function neopets_connect($cookiefile){
$username = "user";
$password = "password";
//Connection
$data = neopets_login($username, $password, $cookiefile);
//On met la page en français
$page = "http://www.neopets.com/index.phtml";
$arrayPost = array();
$arrayPost["lang"] = "fr";
$data = curl_post("http://www.neopets.com/index.phtml",$cookiefile,$arrayPost);
return $data;
}
///////////////////////////////////////////////
// Décoder la page
///////////////////////////////////////////////
function decodePage($data){
$result = utf8_decode($data);
return $result;
}
$cookiefile = tempnam("", "neopets_");
neopets_connect($cookiefile); |