Here is my php code that checks random.txt file for texts and randomly show one of them.
<?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">
Here is what inside my random.txt file.
Jack
Binsky
Igor
Ivan
Eva
I want my code to show this names to a visitor only once. It means if someone visit my webpage from an IP address, the page will show a name randomly from the .txt file. But it won't show that name second time for that IP address if the visitor reloads the webpage.
How can I do that?
Aucun commentaire:
Enregistrer un commentaire