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
Solved

Random Meta Refresh, with log.

Posted on 2001-06-16
10
356 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fulfillment API php code sample 1 57
Is there an elegant way to view sql statements written in PDO? 2 22
Custom Wordpress Loop 22 38
AJAX Wordpress Not Reading Variable 2 27
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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