GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php help (https://gfy.com/showthread.php?t=764207)

ztik 08-28-2007 02:05 PM

php help
 
so I am trying make a script that will goto 1 url or the other randomly

I figured I would make it select a random number then if $num = 1 goto www.google.com and if $num = 2 then goto www.yahoo.com

I can't seam to get it to work I can however get the number part to work


<?php

$num = mt_rand(1, 2);
echo($num);



?>



how would I go about finishing that?

calmlikeabomb 08-28-2007 02:19 PM

PHP Code:

<?php

ob_start
();

list(
$num$url) = array(mt_rand(01), array('http://www.yahoo.com/''http://www.google.com/'));

header("Location: $url[$num]"); ob_flush(); exit();

?>

Use the url array to store the address you want to redirect to. The first parameter of mt_rand() must be zero, because the first index of an array is always 0 then, 1, 2, 3, etc. You'll want the second parameter to be total number items in the array. Don't forget the first item in the array is indexed as 0.

fris 08-28-2007 02:28 PM

Levi can you msg me i been trying to reach you for over a week

fluffygrrl 08-28-2007 02:32 PM

What he said. Not sure you actually need the ob_start, you could echo a javascript redirect, depending what works for you.

calmlikeabomb 08-28-2007 02:38 PM

@Fris, yeah I got your support ticket this morning. Haven't been on AIM much and had to disconnect my phone lines. College semester started 2 weeks ago been keeping me busy that's all..

@fluffygrrl, You don't in that example, but it's still good practice.

fris 08-28-2007 02:41 PM

can you please hit me up when you can? thanks

BIGTYMER 08-28-2007 03:08 PM

PHP Code:

<?php
$url1 
'http://www.google.com';
$url3 'http://www.yahoo.com';
$lnk = array(); 
$lnk[count($lnk)] = $url1;
$lnk[count($lnk)] = $url2;
$count count($lnk); $i date(s); $i $i%$count; if($lnk[$i]){ $url $lnk[$i]; } else { $url $url1; }
header"Location: "$url );
?>

I'm not 100% sure what you need. That is one way to do it.


All times are GMT -7. The time now is 12:46 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123