Advertisement
Combreal

equ2nddeg.php

Jul 19th, 2020
1,500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 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. $content = getContent("https://www.newbiecontest.org/epreuves/prog/prog6.php", 'C:/Temp/cookies.txt');
  24. $equation = substr($content, 54);
  25. $equation = substr($equation, 0, -4);
  26. echo $equation . "<br />";
  27.  
  28. $array = preg_split("/x/", $equation);
  29. $array[1] = substr($array[1], 2);
  30. if(empty($array[0]))
  31. {
  32.     echo "a is empty <br />";
  33.     $intA = 1;
  34. }
  35. else
  36. {
  37.     $intA = $array[0][0];
  38. }
  39. $intA = (int) $intA;
  40. echo "a : " . $intA . "<br />";
  41. if (strlen($array[1])>3)
  42. {
  43.     //got to add b = 10 case
  44.     $intB = substr($array[1], -1);
  45. }
  46. else
  47. {
  48.     $intB = 1;
  49. }
  50. $intB = (int) $intB;
  51. if (!strcmp($array[1][1], '-'))
  52. {
  53.     $intB = -$intB;
  54. }
  55. echo "b : " . $intB . "<br />";
  56. if(empty($array[2]))
  57. {
  58.     $intC = 0;
  59. }
  60. else
  61. {
  62.     $intC = substr($array[2], -1);
  63.     if (!strcmp($array[2][1], '-'))
  64.     {
  65.         $intC = -$intC;
  66.     }
  67. }
  68. echo "c : " . $intC . "<br />";
  69. $delta = $intB * $intB * - 4 * $intA * $intC;
  70. echo "delta : " . $delta . "<br />";
  71. $x1 = (-$intB - sqrt($delta))/(2*$intA);
  72. $x1 = round($x1, 2);
  73. echo "x1 : " . $x1 . "<br />";
  74. $x2 = (-$intB + sqrt($delta))/(2*$intA);
  75. $x2 = round($x2, 2);
  76. echo "x2 : " . $x2 . "<br />";
  77. if ($x1 < $x2)
  78. {
  79.     echo "Highest is : " . $x2 . "<br />";
  80.     $solution = $x2;
  81. }
  82. else
  83. {
  84.     echo "Highest is : " . $x1 . "<br />";
  85.     $solution = $x1;
  86. }
  87. $subm = "https://www.newbiecontest.org/epreuves/prog/verifpr6.php?solution=" . $solution;
  88. header("Location: $subm");
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement