[英]How to restrict access to a php file to once per day? (specifically, the php file sends an e-mail, I want one e-mail per day per user/IP)
[英]How to choose one line from a file per day?
我會解釋更多
我有文件名為date.php
打來電話,文本文件word.txt
。 我在word.txt
放了更多箴言
現在,每天我只需要從word.txt
打印一個諺語,就像這樣:
有人可以幫我這個想法嗎?
$proverbs = file('word.txt');
echo $proverbs[(int)date('z')%count($proverbs)];
如果是一周輪換(即每個工作日一個諺語),我會這樣做:
$proverbs = array(
# Monday
"Build a man a fire, and he'll be warm for a day.
Set a man on fire, and he'll be warm for the rest of his life.
-- Terry Pratchett",
# Tuesday
"The pen is mightier than the sword if the sword is very short,
and the pen is very sharp
-- Terry Pratchett",
# Wednesday
"....",
# Thursday
"...."
);
$current_weekday = date("N"); # 1 = Monday ... 7 = Sunday
echo $proverbs[$current_weekday];
您可以使用文件功能從文件中讀取。
假設您將新諺語放在頂部,則可以執行以下操作:
$lines = file('word.txt');
echo $lines[0]; // displays the first line
$proverbs = file('word.txt');
$today = (int)date('N');
echo $proverbs[$today - 1];
只需將所有諺語放在文本文件的新行中即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.