Php随机页面网址自动重新加载
Php random page url automatic reload
我正在尝试让下面的这个 php 脚本自动在下面将页面快速重新加载到包含网站页面的文件夹中的随机页面。我拥有的代码只显示文本链接或什么都没有,并且不会自动重新加载到随机页面。这是代码:
<?php
//set the urls
$urls = array("1.html" ,"2.html" ,"3.html" ,"4.html" ,"5.html" ,"6.html" ,"7.html" ,"8.html" ,"9.html"
,"10.html" ,"11.html" ,"12.html" ,"13.html" ,"14.html" ,"15.html" ,"16.html" ,"17.html" ,"18.html" ,
"19.html" ,"20.html" ,"21.html" ,"22.html" ,"23.html" ,"24.html" );
//set the number in (rand()%3); for however many links there are
$random = (rand()%24);
echo ("<a href = '"$urls[$random]");
?>
因此,如果我有一个用户在 3.html 上的页面,并且他们单击了一个按钮,我希望脚本运行并从该数组中加载另一个随机页面,并在 URL 框中立即将页面重新加载到该页面。
3.html看起来像这样,这是按钮自动页面加载JavaScript的代码:
<h2 id="correct">CORRECT</h2>
<h2 id="wrong">WRONG</h2>
<div id="answerswers">
<button onclick="document.getElementById('wrong').style.visibility='visible';
window.location = 'random.php';" id="one">1986</button>
<button onclick="document.getElementById('correct').style.visibility='visible';
window.location = 'random.php';" id="two">1913</button>
<button onclick="document.getElementById('wrong').style.visibility='visible';
window.location = 'random.phprandom.php';" id="three">1723</button>
<button onclick="document.getElementById('wrong').style.visibility='visible';
window.location = 'random.php';" id="four">1812</button>
</div>
请帮我修复代码!
另外,如果链接用数字标记,是否有更简单的方法将这些页面添加到数组中。意思是我可以用一行代码做到这一点吗?
删除回声线并将其替换为:
header("Location: ".$urls[$random]);
exit;
如果您知道所有页面都是数字,则可以执行以下操作:
$url = rand(1,24).'.html';
header("Location: ".$url);
exit;
这应该可以解决问题(如果您在标题函数之前没有在网站上打印任何内容)
header("Location: /"rand(1,24).".html");
exit;
相关文章:
- 创建新数据和加载现有数据需要单独的视图吗
- 钛 - HTTPClient:打开新的控制器加载
- 保持 JavaScript 在浏览器控制台中运行,即使在新的页面加载之后也是如此
- 路由到新页面时加载不起作用
- 如何在新窗口完成加载后执行某些内容
- 使用新标题重新加载 html 页面
- Primefaces在打开新页面时加载数据消息
- Wordpress音频播放器和平滑状态.在新页面重新加载播放器时调用什么回调函数
- 用新数据重新加载renderer3d
- 文本不被渲染后,新的页面加载- JQuery移动
- 需要在新标签中加载pdf/doc文件,而不是下载,只是想在浏览器中阅读
- 用新参数重新加载页面
- Js和CSS不检测新页面何时加载
- 在新页面上加载一个flash视频,它在上一页上的位置
- 在新窗口中加载代码编写器视图
- 在控制台中使用新脚本重新加载页面
- 如何在加载新页面后加载AJAX数据
- 如何使用jQuery在新窗口中加载页面,然后关闭它们
- Jquery没有看到新的HTML加载到对话框中
- 无法用新值重新加载JGrid