FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Random page or directory





Josso
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.
mathiaus
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!
Josso
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 Sad
MrBlueSky
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 Sad


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.
mathiaus
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).
gerpg
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.
ronaldallan.mojica
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...

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
Related topics
Google banned my site!!
Random page generator
Creating a new Operating System
LOST
PHP Editor in Frihost Direct Admin Server?
some help scripting cgi
Pulling quotes from wikiquote
how often does spiders crawl your pages
Whats your Internet Home Page ?
Is CSS a replacement of tables or assisting method of them ?
Weird Yahoo Slurp behaviour
HTTP ERROR 403
Op zoek naar een speciaal script. (Random pagina)
New math problem a vector floating in space
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.