Thursday, 15 September 2011

php - Please help me save data sent by the server in response to my cURL GET request -



php - Please help me save data sent by the server in response to my cURL GET request -

i trying larn php doing may find useful myself. there betting agency in country has website can check if won or not entering ticket number. trying write php script check if range of tickets worth don't have come in every ticket manually on website.

i managed that. want save response server in file. run serious problems this. managed save verbose file unable create script save file see on screen within browser after running script.

here code:

<?php function check($week, $base, $startcheck, $endcheck, $verbose = "true"){ // set file path $verbosepath = 'publicbet.txt'; echo "saving tickets to: <b>$verbosepath</b>\n"; // initiate numbering $i = 0; // initiate publicbet.ro ip $ip = "80.86.107.93"; // loop while ($startcheck <= $endcheck){ // generate tickkey $tickkey = $week.$base.$startcheck; // current server time $time = date('d-m-y h:i:s'); // open 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 checking ip adress // $tickkey sent in order // check abnormalities; send // ip adress of website:) $headerarray = array( "x-forwarded-for: $ip"); // set url , other options curl_setopt($ch, curlopt_url, 'http://publicbet.ro/gettickinfo2.php?lang=ro&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 scheme resources curl_close($ch); fclose($f); // showing informtion $v .= "<br />$i. @ <b>$time</b> server checked tickkey: <b>$tickkey</b> , returned tickket: "; if ($verbose == "true"){ echo $v; $v = ''; } // modifying values $startcheck++; $i++; } } if ($_post[week] && $_post[base] && $_post[startcheck] && $_post[endcheck]){ check($_post[week], $_post[base], $_post[startcheck], $_post[endcheck]); } else { ?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>publicbet.ro</title> </head> <body> <h1>check tickets here</h1> <form action="<?php echo $_server[php_self];?>" method="post"> <table> <tbody> <tr> <td>week:</td> <td>base:</td> <td>start check:</td> <td>end check:</td> </tr> <tr> <td><input type="number" name="week" min="00" max="54" maxlength="2" size="2" value=""/></td> <td><input type="number" name="base" maxlength="11" size="11" value=""/></td> <td><input type="number" name="startcheck" maxlength="6" size="6" value=""/></td> <td><input type="number" name="endcheck" maxlength="6" size="6" value=""/></td> </tr> </tbody> </table> <br /><input type="submit" value="check!" /> </form> </body> </html> <?php } ?>

so please tell me if there method of doing willing to. pleased.

if want test script utilize these values: week: 05 base: 16010234203 start check: 350900 end check: 350920 .

it homecoming 19 false tickets , 1 true. want text showing exported text file rather showing on screen.

is there way this?

thank in advance.

set curlopt_returntransfer true, , curl_exec(), assign variable this:

$data = curl_exec($ch)

then can save this:

file_put_contents('my_file.txt', $data);

use constants instead of string literals things true , false etc.. see in function arguments $verbose = "true", replaced $verbose = true.

you using constants should using string literals, illustration $_post[base] should $_post['base'] or $_post["base"]

please don't utilize $_server['php_self'] that, leaves open xss attacks, etc. can action="" , post page in question, php_self

where doing

if($_post[base] .....)

i recommend doing instead:

if(isset($_post['base'], $_post['somethingelse'], $_post['anotherfield'])) { // yay }

php html curl

No comments:

Post a Comment