使用php、函数参数写入文件
我在用php写入文件时遇到问题。我有一个随机生成器功能(彩票系统),我所需要的就是在它生成一个数字后更改使用php、函数参数写入文件,php,file,Php,File,我在用php写入文件时遇到问题。我有一个随机生成器功能(彩票系统),我所需要的就是在它生成一个数字后更改轮号 function getRandomNumber() { $fn = "roundID.txt"; $file = fopen($fn, "r"); $round_id = fread($file,filesize($fn)); fclose($file); $server_seed = "39b7
轮号
function getRandomNumber() {
$fn = "roundID.txt";
$file = fopen($fn, "r");
$round_id = fread($file,filesize($fn));
fclose($file);
$server_seed = "39b7d32fcb743c244c569a56d6de4dc27577d6277d6cf155bdcba6d05befcb34";
$lotto = "0422262831";
$hash = hash("sha256",$server_seed."-".$lotto."-".$round_id);
$roll = hexdec(substr($hash,0,8)) % 15;
echo "$roll";
setNewRound($round_id);
}
在这4行中,我打开文件并读取它(文件中只有一个数字)。接下来的4行是彩票系统,在最后两行中,我正在拨打生成的号码,我想设置新一轮(最后一轮+1)。我使用了如下函数:
function setNewRound($current_round) {
$fn = "roundID.txt";
$file = fopen($fn, "w");
$new_round = $current_round++;
fwrite($file, $new_round);
fclose($file);
}
第一个函数工作得很好,但第二个函数完全不想工作…使用$new\u round=$current\u round++
赋值后会增加。使用+$current\u round
或简单地使用$current\u round+1
。您可能也没有该文件的写入权限,不确定。请先试试@lafor的建议。您也可以使用和来读/写文件。@lafor非常感谢。