Advertisement
Combreal

prog9.php

Jul 20th, 2020
1,730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2. function getContent($url, $cookiePath)
  3. {
  4.     //used Export Cookies extension to get NC cookie
  5.     $ch = curl_init ();
  6.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  7.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  8.     curl_setopt ( $ch, CURLOPT_URL, $url );
  9.     curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  10.     curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  11.     curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 0 );
  12.     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiePath);
  13.     curl_setopt($ch, CURLOPT_VERBOSE, true);
  14.     $file_contents = curl_exec ( $ch );
  15.     if (curl_errno ( $ch )) {
  16.         echo curl_error ( $ch );
  17.         curl_close ( $ch );
  18.         exit ();
  19.     }
  20.     curl_close ( $ch );
  21.     return $file_contents;
  22. }
  23.  
  24. function getPrice($procName, $ramName, $procDenomList, $procPrices, $ramDenomList, $ramPrices)
  25. {
  26.     $totalPrice = 0;
  27.     for ($i=0;$i<9;$i++)
  28.     {
  29.         if (strpos($ramDenomList[$i], $ramName) !== false)
  30.         {
  31.             if ($i == 8)
  32.             {
  33.                 $totalPrice += 0;
  34.             }
  35.             else
  36.             {
  37.                 $totalPrice += $ramPrices[$i];
  38.             }
  39.         }
  40.     }
  41.     for ($j=0;$j<10;$j++)
  42.     {
  43.         if (strpos($procDenomList[$j], $procName) !== false)
  44.         {
  45.             if ($j == 0)
  46.             {
  47.                 $totalPrice += 0;
  48.             }
  49.             else
  50.             {
  51.                 $totalPrice += $procPrices[$j];
  52.             }
  53.         }
  54.     }
  55.     return $totalPrice;
  56. }  
  57.  
  58. $content = getContent("https://www.newbiecontest.org/epreuves/prog/prog9/epreuve9.php", 'C:/Temp/cookies.txt');
  59. $splitPrice = explode("<tr align='center'>", $content);
  60. $priceSize = count($splitPrice);
  61. $ramID = 0;
  62. for ($j=1;$j<10;$j++)
  63. {
  64.     $denom = strip_tags($splitPrice[$j]);
  65.     $splitPri = explode(" ", $denom);
  66.     $ramPrice[$ramID] = (int) substr($denom, -5);
  67.     $ramDenomList[$ramID] = $splitPri[0] . " " . $splitPri[1] . " " . $splitPri[2];
  68.     if ( $j != 8 || $j != 9)
  69.     {
  70.         $ramDenomList[$ramID] = substr($ramDenomList[$ramID], 0, -5);
  71.     }
  72.     if ( $j == 9 )
  73.     {
  74.         $ramPrice[$ramID] = "Trop chère ;)";
  75.     }
  76.     //echo "Label : " . $ramDenomList[$ramID] . "<br />";
  77.     //echo "Price : " . $ramPrice[$ramID] . "<br /><br />";
  78.     $ramID++;
  79. }
  80. $procID = 0;
  81. for ($j=10;$j<$priceSize;$j++)
  82. {
  83.     $procList = strip_tags($splitPrice[$j]);
  84.     $procPrice[$procID] = (int) substr($procList, -4);
  85.     $splitprocList = explode(" ", $procList);
  86.     $procDenomList[$procID] = substr($procList, 0, -6);
  87.     if ( $j == 10 )
  88.     {
  89.         $procDenomList[$procID] = substr($procList, 0, -19);
  90.         $procPrice[$procID] = "N'existe plus ;)";
  91.     }
  92.     if ( $j == 19 )
  93.     {
  94.         $procPrice[$procID] = (int) substr($procList, -11);
  95.     }
  96.     //echo "Label : " . $procDenomList[$procID] . "<br />";
  97.     //echo "Price : " . $procPrice[$procID] . "<br /><br />";
  98.     $procID++;
  99. }
  100. $parse = explode("\n", $content);
  101. $config = $parse[17];
  102. $splitConfig = explode(". ", $config);
  103. $i=0;
  104. $listSize = count($splitConfig);
  105. foreach ($splitConfig as &$conf)
  106. {
  107.     if ( $i <= $listSize -2 )
  108.     {
  109.         $splitConf = explode(" ", $conf);
  110.         $name[$i] = $splitConf[0];
  111.         echo "Nom : " . $name[$i] . "<br />";
  112.         $proc[$i] = $splitConf[5] . " " . $splitConf[6];
  113.         echo "Proc : " . $proc[$i] . "<br />";
  114.         $ram[$i] = $splitConf[10] . " " . $splitConf[11] . " " . $splitConf[12];
  115.         echo "RAM : " . $ram[$i] . "<br />";
  116.         $totalPrice[$i] = getPrice($proc[$i], $ram[$i], $procDenomList, $procPrice, $ramDenomList, $ramPrice);
  117.         echo "Price : " . $totalPrice[$i] . "<br /><br />";
  118.     }  
  119.     $i++;
  120. }
  121. $maxPrice = max($totalPrice);
  122. echo "Most expencive : " . $maxPrice . "<br />";
  123. $maxPriceId = array_search($maxPrice, $totalPrice);
  124. echo "From : " . $name[$maxPriceId] . "<br />";
  125. $subm = "http://www.newbiecontest.org/epreuves/prog/prog9/verifpr9.php?prenom=" . $name[$maxPriceId] . "&prix=" . $maxPrice;
  126. echo $subm;
  127. header("Location: $subm");
  128. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement