• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Random Meta Refresh, with log.

Hello,

I am not sure if i can do this with php or not. I know i can with ASP, but would rather not. If anyone has any ideas of another lang to use that works with most web servers, that would be great to.

Here is the problem.
I want a page, that when a user comes to the page, it instantly redirects them ( meta refresh ), but i want them to go to a random page, that is picked from a text file. Also, I would like the random engine to note where the person was sent, and delete that from the list. So if there were 5 pages, and someone went to number 2, someone to number 3, on the next load, the random would only be able to choose from 1,4 or 5. Then, once all 5 or how many there will be ( probably 300-500 pages ) are used, the program will start over, with all available, taking one off the list again as it is used.

Source would be great, any ideas would be cool. I am using this to send kids in a class to random pages, there are hundreds of pages the teacher wants them to view, but each child that visits the computer lab, anywhere from 200-500 kids a day, to get a differnet page, together, each kids data they find on that page, will make a total solution, i guess they are trying to instill mass team work. Thank you - E-mail if needed Redrumkev@hotmail.com

Redrumkev
0
redrumkev
Asked:
redrumkev
  • 6
  • 4
1 Solution
 
redrumkevAuthor Commented:
once the page is viewed, i don't want it deleted premenatly from the text file, just noted so that it won't be used again. Just wanted to clear that up. Thanks
0
 
higijjCommented:
Well.. I would first suggest you do that with MySQL ;-)
Would be faster and easier to maintain because you could make a little admin panel that add/remove/edit the pages to be viewed. I know you could do the same with txt file.. but I really do think it would be easier with MySQL. So.. the code below is for MySQL/PHP.

Here is the definition of the table tbl_name

CREATE TABLE tbl_name (ID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, url CHAR(255), viewed ENUM('no', 'yes') DEFAULT 'no')


Here is the code source of the page that would redirect the students:

<?

$SQLHost = "localhost";
$SQLUser = "sql_username";
$SQLPassword = "sql_password";
$SQLDatabase = "your_database_name";


$link = mysql_connect($SQLHost, $SQLUser, $SQLPassword) OR DIE ("Unable To Connect To Database");
     
     // Connect and get 1 pages randomly from the database
     mysql_select_db($SQLDatabase, $link) OR DIE("Unable To Select To Database");
     $sql = "SELECT ID, url FROM tbl_name WHERE viewed='no' ORDER BY RAND() LIMIT 1";
     $result = mysql_query($sql);

     // Mark the page as been viewed so it does not
     // come up more than 1 time until all pages have been viewed
     while ($row = mysql_fetch_array($result)) {

          $sql = "UPDATE tbl_name SET viewed='yes' WHERE ID='$row[ID]'";
          mysql_query($sql);

     } // end while
     
     // If all pages have been viewed, reset them all
     // and pick a page again!
     if (mysql_num_rows($result) != 1) {

          $link2 = mysql_connect($SQLHoST, $SQLUser, $SQLPassword) OR DIE ("Unable To Connect To Database");
                   
               // reseting the pages..
               mysql_select_db($SQLDatabase, $link2) OR DIE("Unable To Select Database");
               $sql = "UPDATE tbl_name SET viewed='no'";
               mysql_query($sql);
               
               // picking a new page
               $sql = "SELECT ID, url FROM tbl_name WHERE viewed='no' ORDER BY RAND() LIMIT 1";
               $result = mysql_query($sql);
          mysql_close($link2);

     }// end if

mysql_close($link);

// print the meta refresh with the correct URL ..
while ($row = mysql_fetch_array($result)) {

     print "<HTML><BODY><meta http-equiv=\"Refresh\" content=\"0; URL=" . $row[url] .  "\"></BODY></HTML>";

} // end while


?>

Hope this work! ;-)
I haven't tried it..
0
 
higijjCommented:
you could also import your txt file into MySQL ..
so it wouldn't take too long to add ..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
higijjCommented:
you could also replace the meta refresh by a redirection header..

so instead of

print "<HTML><BODY><meta http-equiv=\"Refresh\" content=\"0; URL=" . $row[url] .  "\"></BODY></HTML>";


it would be:

header("Location: $row[url]");

;-)
0
 
higijjCommented:
So.. does it work??
0
 
redrumkevAuthor Commented:
reply...

I am not at work until tomorrow, and my not have a chance to try it until tuesday, but I was reading thur the code on here, and it seems to make sense. So I would say it probably does work. I will try it, and if it does,... you get the points, if it doesn't... i will post on here... the errors that i get. Thank you for responding so quickly.

redrumkev
0
 
higijjCommented:
Alright then!

Let's see what happen with that code when you get a chance!

Regards,
Higijj!
0
 
higijjCommented:
And? Worked??
0
 
redrumkevAuthor Commented:
nasty crash at work. I will be getting to it though, thank you for your patince. I am going to try and bring the software home, and install it on my own computer, so i can work with it. thank you!
0
 
redrumkevAuthor Commented:
I have not had a chance to run this yet, I will need a few more days to try it, lots of problems going on here, with unrelated issues. If I run into any problems with this, could I still ask you for some help? How do I get ahold of you? My e-mail is redrumkev@hotmail.com, please let me know if I can mail you from that, by you sending me an e-mail. Thanks for you time and help!

redrumkev
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now