Skip to content
WJunction - Webmaster Forum

[PHP] Visit Random Site

Status
Not open for further replies.
Needed this script for one of my sites so I just coded it up in minute or two.

PHP:
<?php
$lesites = array(
    'http://www.warezlobby.org/',
    'http://www.atomicwarez.com/',
    'http://www.warezsearch.org/'
);

$randsite = $lesites[array_rand($lesites)];

header('Location: '.$randsite);
die('<a href="'.$randsite.'">Click here if you have not been redirected</a>');
?>
 

14 comments

By the way just thought of something you should do incase the browser is old and shitty

replace exit with die('<a href="'.$lesites[array_rand($lesites)].'">Click here if you are not redirected</a>');

I wouldnt be me if I didnt offer a improvement now would I?
 
i had to inprove it just a lil

PHP:
<?php
$lesites = array(
    'http://www.warezlobby.org/',
    'http://www.atomicwarez.com/',
    'http://www.warezsearch.org/'
);

$randsite = $lesites[array_rand($lesites)];

((headers_sent() === false) ? header('Location: '.$randsite) : die('<a href="'.$randsite.'">Click here if you have not been redirected</a>'));
?>
 
PHP:
 <?php
$lesites = array(
    'http://www.warezlobby.org/',
    'http://www.atomicwarez.com/',
    'http://www.warezsearch.org/'
);

$randsite = $lesites[array_rand($lesites)];

((headers_sent() === false) {
header('Location: '.$randsite);
die('<a href="'.$randsite.'">Click here if you have not been redirected</a>'));
}else{
die('<a href="'.$randsite.'">Click here if you have not been redirected</a>'));
}
?>
 
Splitice, you know thats not good coding lol, why check if headers_sent and then die an href under the same expression.... just need to remove the first href out the if lol
 
And hers a smaller edit

PHP:
<?php
$lesites = array(
    'http://www.warezlobby.org/',
    'http://www.atomicwarez.com/',
    'http://www.warezsearch.org/'
);

$randsite = $lesites[rand(0,count($lesites))]; // lil faster using count rather than array rand

((headers_sent() === false) ? header('Location: '.$randsite) : die('<a href="'.$randsite.'">Click here if you have not been redirected</a>'));
?>
 
^

Code:
$randsite = $lesites[rand(0,count($lesites))];

Should be

Code:
$randsite = $lesites[rand(0,count($lesites)-1)];

And yeah, I started with rand() first but then switched to array_rand because it was shorter.
 
Ah my bad on the -1 I was testing the code just writing it in.... missed that lol and yea such short code it don't make a difference just sum said it in simplest for so thought i would iterate lol
 
Status
Not open for further replies.

About the author

C
Active Member · Joined
1,493
Messages
2
Reactions
38
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom