Jump to content

Random Links


CoolAffiilate

Recommended Posts

Hello everyone,

 

    Maybe you can help me figure out what I am doing wrong. I am trying to split test 2 affiliate links. The user is sent to a PHP file and the file will randomly pick a link, and forward the user. But, the code is not working. Here is what I have tried.

 

 

Try #1

 

<?php

$webarray = array("http://www.site1.com",

    "http://www.site2.com",

    "http://www.site3.com",

    "http://www.site4.com";

$rand = rand(0,size($webarray));

header( 'Location: '.$webarray[$rand]) ;

?>

 

Gives an Error Line 5.

 

Try #2

 

<?php

$rand = rand(1,2);

if($rand =1)

  header( 'Location: http://www.site1.com' ) ;

else

  header('Location: http://www.site2.com);

?>

 

Just goes to the 1st rand. Will not even go to the 2nd site.

 

Thanks!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.