Hey, I was wondering if I could create some PHP which redirects to a random page or directory on a website. It would have to cover all of the files in the sub-directories as well. The only reason I ask this is because I don't want to have to list all the pages in the code because there will be a lot.
Random page or directory
Yes but it needs to have a list of ages somewhere. Either list in a file, database or the code will need to search for and find pages each time it runs which is bad!
Oh yeah that's a good point - I think I may just have to add a page to the code every time I make one 
| Josso wrote: |
| Oh yeah that's a good point - I think I may just have to add a page to the code every time I make one |
If you don't want the pages in your code, and don't want to add them by hand, you can store them in a textfile. When the script needs a random page it chooses a random line from the textfile and jumps to that page. To create the file containing the file-list you can write a little PHP script which traverses the directory tree of files you want to use recursively. You have to run this script only when you add (or remove) files.
For dynamic sites though where the files themselves are not the URL, adding pages manually is ore ideal unless you create a script to read links from your pages and store them all (sort of like a spider).
Its 12:30am so im going to be really brief...
it is possible, all you have to do is list the directory with php functions, number them and then create a random number generation from 1 to the 'count' of the scripts inside that directory, then set the page url as a variable and put it into the header(); function or a alternate redirect html, java, watever tickles your fancy.
Louis.
it is possible, all you have to do is list the directory with php functions, number them and then create a random number generation from 1 to the 'count' of the scripts inside that directory, then set the page url as a variable and put it into the header(); function or a alternate redirect html, java, watever tickles your fancy.
Louis.
hello...
if you like you can create an array that contain the pages you want to randomized...
and then use the function rand() and header()... this how you do it...
first create an array with the url you want to redirect...
this approach is very simple but also you can use database for more complex and better managing the urlss ...
hopefully it may help you
if you like you can create an array that contain the pages you want to randomized...
and then use the function rand() and header()... this how you do it...
first create an array with the url you want to redirect...
| Code: |
|
<?php /*you can add more links here*/ $urlList = array( 'http://yahoo.com', 'http://frihost.com', 'http://google.com', ); count the number of items in the $urlList $numArray = count($urlList); /*randomize a number from 1 to the number of items in the array $urlList */ $urlID = rand(1,$numArray); /*Redirect the url */ header('Location: '.$urlList[$urlID]); ?> |
this approach is very simple but also you can use database for more complex and better managing the urlss ...
hopefully it may help you
