Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

hannibal775 on "redirect to a random url stored in an array"

$
0
0

Hi. I'm trying to run a snippet of php in a page on my site. I am new to php, but I have enough of an understanding of programming languages to do simple things. I have figured out how to execute a php code snippet in a page and have been successful (as in adding the current date and time) but I can't seem to get the following code to work. I am trying to do a random redirect to a group of URLs stored in an array. It works when I test the code outside of Wordpress, but I'm not sure how to get it to work inside a page. Ideally, I'd prefer to have a button execute the snippet, but I would settle for it happening automatically what the page loads. Can anybody give me some guidance on this matter? It would be greatly appreciated. I am building on a local network at the moment, so I do not have a link to the site.

This is what I've got:

<?php $aff_array = array("URL1", "URL2","URL3");
    header("Location: ".$aff_array[rand(0,2)]); exit(); ?>

Thanks in advance!!


Viewing all articles
Browse latest Browse all 8245

Trending Articles