php - 显示 .txt 文件中的随机文本,但每个 IP 地址仅显示一次
问题描述
这是我的 php 代码,用于检查 random.txt 文件中的文本并随机显示其中一个。
<?php
//Path of file
$myFile = "random.txt";
//Read file from array
$lines = file($myFile);
//Get number line of file
$lineTotal = count($lines);
//Remove 1 line (start from 0)
$count = $lineTotal-1;
//Get casual number
$number_casual = rand(0,$count);
//Print line 2 ([0] = 1 ; [1] = 2 ; ...)
?>
<input name="accesspin" style="width: 300px" value="<?php echo htmlentities( $lines[$number_casual] ); ?>" size="36">
这是我的 random.txt 文件中的内容。
Jack
Binsky
Igor
Ivan
Eva
我希望我的代码仅向访问者显示此名称一次。这意味着如果有人从 IP 地址访问我的网页,该页面将随机显示 .txt 文件中的名称。但如果访问者重新加载网页,它不会第二次显示该 IP 地址的名称。
我怎样才能做到这一点?
解决方案
推荐阅读
- python - 在我的 Conda 环境中哪里安装 pip 包?
- dependency-injection - Xamarin 依赖注入失败 - 尝试获取特定于平台的实现时崩溃
- javascript - setState() 之后的 Console.log() 不返回更新的状态
- java - 输入验证检查输入是否为双精度
- python - AWS Lambda 层
- javascript - 尝试返回字符串 Nodejs VM 时的引用错误
- java - 如何为实体实现多个@MappedSuperClass 继承
- google-apps-script - 如何将操作单元格更改为在 Google 表格中输入的任何内容
- django - 如何向数据库发出多个请求?
- css - css - 水平自动拉伸按钮