请高手帮忙写几句代码

WBOY
Release: 2016-06-23 14:15:21
Original
876 people have browsed it

我需要在一个页面上显示一个随机数(5位)

要求,这个数字每天变一次,过了凌晨12点就变一下,  刷新不变。


回复讨论(解决方案)

session_start();
if (date("%h %s",time())=="00:00")
{
   $_SESSION['num']=rand(10000,99999);
}
echo $_SESSION['num'];
?>

相同的种子,就产生子昂同的随机数

srand(date('Ymd'));echo rand(10000, 99999);
Copy after login
Copy after login
Copy after login

session_start();
if (date("%h %s",time())=="00:00")
{
$_SESSION['num']=rand(10000,99999);
}
echo $_SESSION['num'];
?>

似乎楼主不需要对用户分,好像只要网站上一天用同一个就行了

相同的种子,就产生子昂同的随机数

srand(date('Ymd'));echo rand(10000, 99999);
Copy after login
Copy after login
Copy after login

版主正解

相同的种子,就产生子昂同的随机数

srand(date('Ymd'));echo rand(10000, 99999);
Copy after login
Copy after login
Copy after login


使用版主的这个方法,一定要注意设置时区,否则可能不是0点变,而是其他时间点变。
date_default_timezone_set(‘Asia/Shanghai');

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!