私は実際に自分に役立つと思うことをしてPHPを学ぼうとしています。私の国には、チケット番号を入力して勝ったかどうかを確認できるWebサイトを持っているベッティングエージェンシーがあります。PHPスクリプトを作成して、チケットの範囲に価値があるかどうかを確認しようとしているので、Webサイトですべてのチケットを手動で入力する必要はありません。
私はなんとかそれをすることができました。しかし今、私は彼らのサーバーから得た応答をファイルに保存したいと思います。私はこれで深刻な問題に遭遇します。冗長ファイルをファイルに保存できましたが、スクリプトの実行後にブラウザ内の画面に表示されるファイルにスクリプトを保存できません。
コードは次のとおりです。
<?php
function check($week, $base, $startcheck, $endcheck, $verbose = "true"){
// Set file path
$verbosePath = 'publicbet.txt';
echo "Saving the 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;
// 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&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 .= "<br />$i. At <b>$time</b> the server checked the tickkey: <b>$tickkey</b> and returned the 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 your 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 } ?>
ですから、私がやりたいことをする方法があるかどうか教えてください。本当に嬉しいです。
スクリプトをテストする場合は、次の値を使用します。週:05ベース:16010234203開始チェック:350900終了チェック:350920。
19個の偽のチケットと1個の真のチケットを返します。表示されているこのすべてのテキストを、画面に表示するのではなく、テキストファイルにエクスポートしたいと思います。
これを行う方法はありますか?
前もって感謝します。