Solved

Random Meta Refresh, with log.

Posted on 2001-06-16
10
351 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP & MySQL - Rounding Results from a Select Query 3 25
Cannot call a static method on an Eloquent object 6 33
error log using ftp 7 41
PHP curl issue VERBOSE output 18 46
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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 …

822 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