Note that there are some explanatory texts on larger screens.

plurals
  1. POPlease help me save data sent by the server in response to my cURL GET request
    text
    copied!<p>I am trying learn PHP by actually doing something I may find useful for myself. There is a betting agency in my country which has a website where I can check if I won or not by entering a ticket number. I am trying to write a PHP script to check if range of tickets are worth anything so I don't have to enter every ticket manually on their website.</p> <p>I managed to do that. But now I want to save the response I get from their server in a file. I run into serious problems with this. I managed to save the verbose into a file but I am unable to make the script save to a file what I see on the screen inside my browser after running the script.</p> <p>Here is the code:</p> <pre><code>&lt;?php function check($week, $base, $startcheck, $endcheck, $verbose = "true"){ // Set file path $verbosePath = 'publicbet.txt'; echo "Saving the tickets to: &lt;b&gt;$verbosePath&lt;/b&gt;\n"; // Initiate numbering $i = 0; // Initiate publicbet.ro IP $ip = "80.86.107.93"; // Loop while ($startcheck &lt;= $endcheck){ // Generate tickkey $tickkey = $week.$base.$startcheck; // get the current server time $time = date('d-m-Y H:i:s'); // Open a new cURL resource $ch = curl_init(); // Stuff curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_STDERR,$f = fopen($verbosePath, "a")); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"); // publicbet.ro may be checking the IP adress // from where the $tickkey is sent in order to // check for abnormalities; we will send the // IP adress of the website:) $headerarray = array( "X-Forwarded-For: $ip"); // Set the URL and other options curl_setopt($ch, CURLOPT_URL, 'http://publicbet.ro/gettickinfo2.php?lang=ro&amp;tickkey='.$tickkey); curl_setopt($ch, CURLOPT_REFERER, 'http://www.publicbet.ro/'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerarray); // Executing cURL curl_exec($ch); // Close cURL resource, free up system resources curl_close($ch); fclose($f); // Showing informtion $v .= "&lt;br /&gt;$i. At &lt;b&gt;$time&lt;/b&gt; the server checked the tickkey: &lt;b&gt;$tickkey&lt;/b&gt; and returned the tickket: "; if ($verbose == "true"){ echo $v; $v = ''; } // Modifying values $startcheck++; $i++; } } if ($_POST[week] &amp;&amp; $_POST[base] &amp;&amp; $_POST[startcheck] &amp;&amp; $_POST[endcheck]){ check($_POST[week], $_POST[base], $_POST[startcheck], $_POST[endcheck]); } else { ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;title&gt;publicbet.ro&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Check your tickets here&lt;/h1&gt; &lt;form action="&lt;?php echo $_SERVER[PHP_SELF];?&gt;" method="post"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;week:&lt;/td&gt; &lt;td&gt;base:&lt;/td&gt; &lt;td&gt;start check:&lt;/td&gt; &lt;td&gt;end check:&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="number" name="week" min="00" max="54" maxlength="2" size="2" value=""/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" name="base" maxlength="11" size="11" value=""/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" name="startcheck" maxlength="6" size="6" value=""/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" name="endcheck" maxlength="6" size="6" value=""/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;br /&gt;&lt;input type="submit" value="Check!" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php } ?&gt; </code></pre> <p>So please tell me if there is any method of doing what I am willing to. I would be really pleased.</p> <p>If you want to test the script use these values: week: 05 base: 16010234203 start check: 350900 end check: 350920 .</p> <p>It will return 19 false tickets and 1 true. I want all this text which is showing up to be exported to a text file rather than showing on my screen.</p> <p>Is there a way to do this?</p> <p>Thank you in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload