IamLupo

Mensa.nl | Thuistest vragen | Antwoorden

Aug 2nd, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.15 KB | None | 0 0
  1. <?php
  2. /*
  3.     Website: http://www.mensa.nl/thuistest/vragen
  4.     Answers:
  5.         1: D
  6.         2: C
  7.         3: B
  8.         4: C
  9.  
  10.         5: A, D
  11.         6: B, C
  12.         7: D, A
  13.         8: B, D
  14.  
  15.         9:  B
  16.         10: D
  17.         11: C
  18.         12: A
  19.         13: C
  20.         14: A
  21.         15: C
  22.  
  23.         16: M
  24.         17: 15
  25.         18: 8
  26.         19: 6
  27.         20: 5
  28.         21: 4
  29.         22: 1
  30.         23: 2
  31.  
  32.         24: C
  33.         25: B
  34.         26: C
  35.         27: D
  36.         28: D
  37.         29: C
  38.         30: C
  39.         31: D
  40.         32: B
  41.         33: A
  42. */
  43.  
  44. ini_set('display_errors', 1); //DEBUG
  45. set_time_limit(100000);
  46.  
  47. class GameResult {
  48.     const BAD   = 0x0;
  49.     const GOOD  = 0x1;
  50.     const GREAT = 0x2;
  51. }
  52.  
  53. class Game {
  54.     private $key;
  55.     private $answers;
  56.     private $starttijd;
  57.     private $tijd;
  58.    
  59.     function Initialize() {
  60.         $this->answers = array(
  61.             "q1" => "d",                    //  D
  62.             "q2" => "c",                    //  C
  63.             "q3" => "b",                    //  B
  64.             "q4" => "c",                    //  C
  65.            
  66.             "q51" => "a", "q52" => "d",     //  A, D
  67.             "q61" => "b", "q62" => "c",     //  B, C
  68.             "q71" => "d", "q72" => "a",     //  D, A
  69.             "q81" => "b", "q82" => "d",     //  B, D
  70.            
  71.             "q9" => "b",                    //  B
  72.             "q10" => "d",                   //  D
  73.             "q11" => "c",                   //  C
  74.             "q12" => "a",                   //  A
  75.             "q13" => "c",                   //  C
  76.             "q14" => "a",                   //  A
  77.             "q15" => "c",                   //  C
  78.            
  79.             "q16" => "M",                   //  M
  80.             "q17" => "15",                  //  15
  81.             "q18" => "8",                   //  8
  82.             "q19" => "6",                   //  6
  83.             "q20" => "5",                   //  5
  84.             "q21" => "4",                   //  4
  85.             "q22" => "1",                   //  1
  86.             "q23" => "2",                   //  2
  87.            
  88.             "q24" => "c",                   //  C
  89.             "q25" => "b",                   //  B
  90.             "q26" => "c",                   //  C
  91.             "q27" => "d",                   //  D
  92.             "q28" => "d",                   //  D
  93.             "q29" => "c",                   //  C
  94.             "q30" => "c",                   //  C
  95.             "q31" => "d",                   //  D
  96.             "q32" => "b",                   //  B
  97.             "q33" => "a",                   //  A
  98.         );
  99.     }
  100.    
  101.     function Start() {
  102.         //Get Page
  103.         curl_setopt(Page::$curl_sessie, CURLOPT_HEADER, false);
  104.         curl_setopt(Page::$curl_sessie, CURLOPT_URL, "http://" . Page::$domein . "/thuistest/vragen");
  105.         $result = curl_exec(Page::$curl_sessie);
  106.        
  107.         //echo $this->updateHTML($result);
  108.        
  109.         //Get Information
  110.         $this->tijd = 0;
  111.         $this->key = $this->getKeyOutofHTML($result);
  112.         $this->starttijd = $this->getStartTijdOutofHTML($result);
  113.        
  114.         //Send Answers
  115.         curl_setopt(Page::$curl_sessie, CURLOPT_URL, "http://" . Page::$domein . "/thuistest/brief");
  116.         curl_setopt(Page::$curl_sessie, CURLOPT_POST, 1);
  117.         curl_setopt(Page::$curl_sessie, CURLOPT_POSTFIELDS, $this->getPostFields());
  118.         $result = curl_exec(Page::$curl_sessie);
  119.        
  120.         //echo $this->updateHTML($result);
  121.        
  122.         //Result
  123.         switch($this->getEndResult($result)) {
  124.             case GameResult::GREAT:
  125.                 echo "GREAT";
  126.             break;
  127.             case GameResult::GOOD:
  128.                 echo "GOOD";
  129.             break;
  130.             case GameResult::BAD:
  131.                 echo "BAD";
  132.             break;
  133.         }
  134.     }
  135.    
  136.     function getPostFields() {
  137.         $result = "key=" . $this->key;
  138.        
  139.         foreach($this->answers as $name => $value)
  140.             $result .=  "&" . $name . "=" . $value;
  141.        
  142.         $result .= "&starttijd=" . $this->starttijd;
  143.         $result .= "&tijd=" . $this->tijd;
  144.        
  145.         return $result;
  146.     }
  147.    
  148.     function getKeyOutofHTML($html) {
  149.         preg_match_all("/name=\"key\" value=\"([a-z0-9]{32})\"/", $html, $output_array);
  150.        
  151.         return $output_array[1][0];
  152.     }
  153.    
  154.     function getStartTijdOutofHTML($html) {
  155.         preg_match_all("/name=\"starttijd\" value=\"(.*?[0-9])\"/", $html, $output_array);
  156.        
  157.         return $output_array[1][0];
  158.     }
  159.    
  160.     function getEndResult($html) {
  161.         //Great
  162.         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);
  163.         if(isset($output_array[0][0]))
  164.             return GameResult::GREAT;
  165.        
  166.         //Good
  167.         preg_match_all("/Jouw intelligentie behoort volgens de resultaten van de Mensa-onlinetest waarschijnlijk tot de hoogste 10% van de bevolking./", $html, $output_array);
  168.         if(isset($output_array[0][0]))
  169.             return GameResult::GOOD;
  170.        
  171.         //Bad
  172.         return GameResult::BAD;
  173.     }
  174.    
  175.     function updateHTML($html) {
  176.         $result = preg_replace("/src=\"/", "src=\"http://" . Page::$domein, $html);
  177.         $result = preg_replace("/href=\"/", "href=\"http://" . Page::$domein, $result);
  178.         return $result;
  179.     }
  180. }
  181.  
  182. class Page {
  183.     public static $domein = "www.mensa.nl";
  184.     public static $curl_sessie;
  185.     public static $game;
  186.    
  187.     public static function Initialize() {
  188.         Page::$curl_sessie = curl_init();
  189.        
  190.         curl_setopt(Page::$curl_sessie, CURLOPT_COOKIESESSION, true);
  191.         curl_setopt(Page::$curl_sessie, CURLOPT_RETURNTRANSFER, true);
  192.         curl_setopt(Page::$curl_sessie, CURLOPT_HEADER, true);
  193.        
  194.         $options = array(
  195.                             "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  196.                             "Accept-Language: en-US,en;q=0.5",
  197.                             "Connection: keep-alive",
  198.                             "Host: www.mensa.nl",
  199.                             "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"
  200.                         );
  201.        
  202.         curl_setopt(Page::$curl_sessie, CURLOPT_HTTPHEADER, $options);
  203.        
  204.         Page::$game = new Game();
  205.     }
  206.    
  207.    
  208.     public static function goHome() {
  209.         curl_setopt(Page::$curl_sessie, CURLOPT_URL, "http://" . Page::$domein . "/lid-worden/doe-de-thuistest");
  210.         curl_exec(Page::$curl_sessie);
  211.     }
  212.    
  213.     public static function Close() {
  214.         curl_close(Page::$curl_sessie);
  215.     }
  216. }
  217.  
  218. Page::Initialize();
  219. Page::goHome();
  220. Page::$game->Initialize();
  221. Page::$game->Start();
  222. Page::Close();
  223.  
  224. ?>
Add Comment
Please, Sign In to add comment