I am trying to have this php script below automatically below reload the page quickly to a random page in a folder with pages for the website. The code I have just shows a text link or nothing and does not automatically reload to a random page. Here is the code:
<?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]");
?>
So if I have a page where user is on 3.html, and they click a button I want the script to run and load another random page out of this array and reload the page to that page right after in the URL box.
3.html looks like this, here is code for the button automatic page load javascript:
<h2 id="correct">CORRECT</h2>
<h2 id="wrong">WRONG</h2>
<div id="answers">
<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>
Please help me fix the code!
Also, is there an easier way to add these pages in the array if the links are labeled by numbers. Meaning can I do this with one line of code?
Aucun commentaire:
Enregistrer un commentaire