Solved

Random Meta Refresh, with log.

Posted on 2001-06-16
10
346 Views
Last Modified: 2006-11-17
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
Comment
Question by:redrumkev
  • 6
  • 4
10 Comments
 
LVL 23

Author Comment

by:redrumkev
ID: 6198912
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
 
LVL 2

Accepted Solution

by:
higijj earned 100 total points
ID: 6199069
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
 
LVL 2

Expert Comment

by:higijj
ID: 6199080
you could also import your txt file into MySQL ..
so it wouldn't take too long to add ..
0
 
LVL 2

Expert Comment

by:higijj
ID: 6199087
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
 
LVL 2

Expert Comment

by:higijj
ID: 6200223
So.. does it work??
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 23

Author Comment

by:redrumkev
ID: 6200838
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
 
LVL 2

Expert Comment

by:higijj
ID: 6200922
Alright then!

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

Regards,
Higijj!
0
 
LVL 2

Expert Comment

by:higijj
ID: 6212304
And? Worked??
0
 
LVL 23

Author Comment

by:redrumkev
ID: 6217137
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
 
LVL 23

Author Comment

by:redrumkev
ID: 6221768
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now