节日节气自动更换图片改进版
此次改进了上次的节气更换图片代码。整体思路不变;
搭建方法和思路点击查看这篇文章:
搭建方法参看之前的那个文章,这次直接贴上代码:
<?php
//获取当前时间
$t=date("m,d");
//国庆
if($t== "10,01"){
$myfile = fopen("放置图片链接的文本文件位置", "w") or die("Unable to open file!");
//修改文本中的链接为下面这个链接
$txt = "需要修改的图片链接";
fwrite($myfile, $txt);
fclose($myfile);
$img=file('放置链接的文本位置') ;
$url =array_rand($img);
//输出图像
header("Location:".$img[$url]) ;
}elseif($t=="10,08"){
$myfile = fopen("同上","w") or die("Unable to open file!") ;
$txt = "同上" ;
fwrite($myfile,$txt) ;
fclose($myfile) ;
$img = file('放置链接的文本位置') ;
$url = array_rand($img) ;
header("Location:".$img[$url]) ;
//如果当前时间不在判断列表则显示文本中的链接,也就是最近显示过的那个图
}else{
$img = file('放置链接的文本位置') ;
$url = array_rand($img) ;
header("Location:".$img[$url]) ;
}
?>
节日节气自动更换图片改进版
https://xsunhua.cn/254.html



共有 0 条评论