Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getContent($url, $cookiePath)
- {
- //used Export Cookies extension to get NC cookie
- $ch = curl_init ();
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt ( $ch, CURLOPT_URL, $url );
- curl_setopt ( $ch, CURLOPT_HEADER, 0 );
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 0 );
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiePath);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- $file_contents = curl_exec ( $ch );
- if (curl_errno ( $ch )) {
- echo curl_error ( $ch );
- curl_close ( $ch );
- exit ();
- }
- curl_close ( $ch );
- return $file_contents;
- }
- function getPrice($procName, $ramName, $procDenomList, $procPrices, $ramDenomList, $ramPrices)
- {
- $totalPrice = 0;
- for ($i=0;$i<9;$i++)
- {
- if (strpos($ramDenomList[$i], $ramName) !== false)
- {
- if ($i == 8)
- {
- $totalPrice += 0;
- }
- else
- {
- $totalPrice += $ramPrices[$i];
- }
- }
- }
- for ($j=0;$j<10;$j++)
- {
- if (strpos($procDenomList[$j], $procName) !== false)
- {
- if ($j == 0)
- {
- $totalPrice += 0;
- }
- else
- {
- $totalPrice += $procPrices[$j];
- }
- }
- }
- return $totalPrice;
- }
- $content = getContent("https://www.newbiecontest.org/epreuves/prog/prog9/epreuve9.php", 'C:/Temp/cookies.txt');
- $splitPrice = explode("<tr align='center'>", $content);
- $priceSize = count($splitPrice);
- $ramID = 0;
- for ($j=1;$j<10;$j++)
- {
- $denom = strip_tags($splitPrice[$j]);
- $splitPri = explode(" ", $denom);
- $ramPrice[$ramID] = (int) substr($denom, -5);
- $ramDenomList[$ramID] = $splitPri[0] . " " . $splitPri[1] . " " . $splitPri[2];
- if ( $j != 8 || $j != 9)
- {
- $ramDenomList[$ramID] = substr($ramDenomList[$ramID], 0, -5);
- }
- if ( $j == 9 )
- {
- $ramPrice[$ramID] = "Trop chère ;)";
- }
- //echo "Label : " . $ramDenomList[$ramID] . "<br />";
- //echo "Price : " . $ramPrice[$ramID] . "<br /><br />";
- $ramID++;
- }
- $procID = 0;
- for ($j=10;$j<$priceSize;$j++)
- {
- $procList = strip_tags($splitPrice[$j]);
- $procPrice[$procID] = (int) substr($procList, -4);
- $splitprocList = explode(" ", $procList);
- $procDenomList[$procID] = substr($procList, 0, -6);
- if ( $j == 10 )
- {
- $procDenomList[$procID] = substr($procList, 0, -19);
- $procPrice[$procID] = "N'existe plus ;)";
- }
- if ( $j == 19 )
- {
- $procPrice[$procID] = (int) substr($procList, -11);
- }
- //echo "Label : " . $procDenomList[$procID] . "<br />";
- //echo "Price : " . $procPrice[$procID] . "<br /><br />";
- $procID++;
- }
- $parse = explode("\n", $content);
- $config = $parse[17];
- $splitConfig = explode(". ", $config);
- $i=0;
- $listSize = count($splitConfig);
- foreach ($splitConfig as &$conf)
- {
- if ( $i <= $listSize -2 )
- {
- $splitConf = explode(" ", $conf);
- $name[$i] = $splitConf[0];
- echo "Nom : " . $name[$i] . "<br />";
- $proc[$i] = $splitConf[5] . " " . $splitConf[6];
- echo "Proc : " . $proc[$i] . "<br />";
- $ram[$i] = $splitConf[10] . " " . $splitConf[11] . " " . $splitConf[12];
- echo "RAM : " . $ram[$i] . "<br />";
- $totalPrice[$i] = getPrice($proc[$i], $ram[$i], $procDenomList, $procPrice, $ramDenomList, $ramPrice);
- echo "Price : " . $totalPrice[$i] . "<br /><br />";
- }
- $i++;
- }
- $maxPrice = max($totalPrice);
- echo "Most expencive : " . $maxPrice . "<br />";
- $maxPriceId = array_search($maxPrice, $totalPrice);
- echo "From : " . $name[$maxPriceId] . "<br />";
- $subm = "http://www.newbiecontest.org/epreuves/prog/prog9/verifpr9.php?prenom=" . $name[$maxPriceId] . "&prix=" . $maxPrice;
- echo $subm;
- header("Location: $subm");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement