Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Website: http://www.mensa.nl/thuistest/vragen
- Answers:
- 1: D
- 2: C
- 3: B
- 4: C
- 5: A, D
- 6: B, C
- 7: D, A
- 8: B, D
- 9: B
- 10: D
- 11: C
- 12: A
- 13: C
- 14: A
- 15: C
- 16: M
- 17: 15
- 18: 8
- 19: 6
- 20: 5
- 21: 4
- 22: 1
- 23: 2
- 24: C
- 25: B
- 26: C
- 27: D
- 28: D
- 29: C
- 30: C
- 31: D
- 32: B
- 33: A
- */
- ini_set('display_errors', 1); //DEBUG
- set_time_limit(100000);
- class GameResult {
- const BAD = 0x0;
- const GOOD = 0x1;
- const GREAT = 0x2;
- }
- class Game {
- private $key;
- private $answers;
- private $starttijd;
- private $tijd;
- function Initialize() {
- $this->answers = array(
- "q1" => "d", // D
- "q2" => "c", // C
- "q3" => "b", // B
- "q4" => "c", // C
- "q51" => "a", "q52" => "d", // A, D
- "q61" => "b", "q62" => "c", // B, C
- "q71" => "d", "q72" => "a", // D, A
- "q81" => "b", "q82" => "d", // B, D
- "q9" => "b", // B
- "q10" => "d", // D
- "q11" => "c", // C
- "q12" => "a", // A
- "q13" => "c", // C
- "q14" => "a", // A
- "q15" => "c", // C
- "q16" => "M", // M
- "q17" => "15", // 15
- "q18" => "8", // 8
- "q19" => "6", // 6
- "q20" => "5", // 5
- "q21" => "4", // 4
- "q22" => "1", // 1
- "q23" => "2", // 2
- "q24" => "c", // C
- "q25" => "b", // B
- "q26" => "c", // C
- "q27" => "d", // D
- "q28" => "d", // D
- "q29" => "c", // C
- "q30" => "c", // C
- "q31" => "d", // D
- "q32" => "b", // B
- "q33" => "a", // A
- );
- }
- function Start() {
- //Get Page
- curl_setopt(Page::$curl_sessie, CURLOPT_HEADER, false);
- curl_setopt(Page::$curl_sessie, CURLOPT_URL, "http://" . Page::$domein . "/thuistest/vragen");
- $result = curl_exec(Page::$curl_sessie);
- //echo $this->updateHTML($result);
- //Get Information
- $this->tijd = 0;
- $this->key = $this->getKeyOutofHTML($result);
- $this->starttijd = $this->getStartTijdOutofHTML($result);
- //Send Answers
- curl_setopt(Page::$curl_sessie, CURLOPT_URL, "http://" . Page::$domein . "/thuistest/brief");
- curl_setopt(Page::$curl_sessie, CURLOPT_POST, 1);
- curl_setopt(Page::$curl_sessie, CURLOPT_POSTFIELDS, $this->getPostFields());
- $result = curl_exec(Page::$curl_sessie);
- //echo $this->updateHTML($result);
- //Result
- switch($this->getEndResult($result)) {
- case GameResult::GREAT:
- echo "GREAT";
- break;
- case GameResult::GOOD:
- echo "GOOD";
- break;
- case GameResult::BAD:
- echo "BAD";
- break;
- }
- }
- function getPostFields() {
- $result = "key=" . $this->key;
- foreach($this->answers as $name => $value)
- $result .= "&" . $name . "=" . $value;
- $result .= "&starttijd=" . $this->starttijd;
- $result .= "&tijd=" . $this->tijd;
- return $result;
- }
- function getKeyOutofHTML($html) {
- preg_match_all("/name=\"key\" value=\"([a-z0-9]{32})\"/", $html, $output_array);
- return $output_array[1][0];
- }
- function getStartTijdOutofHTML($html) {
- preg_match_all("/name=\"starttijd\" value=\"(.*?[0-9])\"/", $html, $output_array);
- return $output_array[1][0];
- }
- function getEndResult($html) {
- //Great
- preg_match_all("/Jouw resultaten van de Mensa-onlinetest waren erg goed. Het blijkt dat jouw intelligentie waarschijnlijk boven het 98e percentiel ligt/", $html, $output_array);
- if(isset($output_array[0][0]))
- return GameResult::GREAT;
- //Good
- preg_match_all("/Jouw intelligentie behoort volgens de resultaten van de Mensa-onlinetest waarschijnlijk tot de hoogste 10% van de bevolking./", $html, $output_array);
- if(isset($output_array[0][0]))
- return GameResult::GOOD;
- //Bad
- return GameResult::BAD;
- }
- function updateHTML($html) {
- $result = preg_replace("/src=\"/", "src=\"http://" . Page::$domein, $html);
- $result = preg_replace("/href=\"/", "href=\"http://" . Page::$domein, $result);
- return $result;
- }
- }
- class Page {
- public static $domein = "www.mensa.nl";
- public static $curl_sessie;
- public static $game;
- public static function Initialize() {
- Page::$curl_sessie = curl_init();
- curl_setopt(Page::$curl_sessie, CURLOPT_COOKIESESSION, true);
- curl_setopt(Page::$curl_sessie, CURLOPT_RETURNTRANSFER, true);
- curl_setopt(Page::$curl_sessie, CURLOPT_HEADER, true);
- $options = array(
- "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "Accept-Language: en-US,en;q=0.5",
- "Connection: keep-alive",
- "Host: www.mensa.nl",
- "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"
- );
- curl_setopt(Page::$curl_sessie, CURLOPT_HTTPHEADER, $options);
- Page::$game = new Game();
- }
- public static function goHome() {
- curl_setopt(Page::$curl_sessie, CURLOPT_URL, "http://" . Page::$domein . "/lid-worden/doe-de-thuistest");
- curl_exec(Page::$curl_sessie);
- }
- public static function Close() {
- curl_close(Page::$curl_sessie);
- }
- }
- Page::Initialize();
- Page::goHome();
- Page::$game->Initialize();
- Page::$game->Start();
- Page::Close();
- ?>
Add Comment
Please, Sign In to add comment