Jump to content

Recommended Posts

Hey all used to be a member a long time ago when i migh have actually know what i was doing :) - started a new site and trying to learn how to do things. Currently i have a button on my webpage that when clicked i would like to have a redirect to a random webpage from a list of my fav pages......My understanding is i need to have the button link to another page which then will figure out what page it wants to goto then redirect the user there. Below is the code i have put together from reading around. But currently for what ever reason its not doing anything and simply brings up a blank page that displays half the code....If possible can somone tell me what stupid mistake i am making with my code below....Thanking you in advance :)

 

<?php
srand ((double) microtime( )*1000000);
$random_number = rand(0,2);

$mypage = "www.kra55.com";

if ($random_number==0)
  $mypage = "www.shortnews.com";
elseif ($random_number==1)
  $mypage = "www.torncity.com";
else
$mypage = "www.kra55.com";


header("Location: http:/" . $mypage);

?> 

Link to comment
https://forums.phpfreaks.com/topic/139646-random-redirect/
Share on other sites

Also, don't forget to put a space between the 'else' and the 'if' (you have elseif in your code).  Also, if I am not mistaken rand() is all inclusive, so you should either put:

 

$random_number = rand(0,1);

 

for two choices, or add another 'else if' statement.

Link to comment
https://forums.phpfreaks.com/topic/139646-random-redirect/#findComment-730666
Share on other sites

another two different ways.

<?php 

$page=array("www.kra55.com","www.shortnews.com","www.torncity.com","www.kra55.com");

shuffle($page);

function head($page){

header("Location: http://{$page[0]}");

return;
}

$random_number=rand(0,4);

switch ($random_number){

case "0";

head($page);

break;

case"1";

head($page);

break;

case"2";

head($page);

break;

case"3";

head($page);

break;

}

?>

 

 

<?php

$page=array("www.kra55.com","www.shortnews.com","www.torncity.com","www.kra55.com");

shuffle($page);

if(isset($page)){

echo header("Location: http://{$page[0]}");
}

?> 

Link to comment
https://forums.phpfreaks.com/topic/139646-random-redirect/#findComment-730676
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.