Solved

Random Meta Refresh, with log.

Posted on 2001-06-16
10
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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
 
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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