Say I have a file named "value.php" . I want it to choose a random value for a variable. <?php $siteaddress = random ?> PHP: Obviously I want to replace "random" with a few web addresses, and select one as random. I then want to make it into an input box in my index page <input type="text" value="php variable" /> Code (markup): So how would I make the variable set to a random address and then apply it to the input? Thanks, BP
If I understand you correctly: $sites=Array("www.google.ca","www.yahoo.ca","www.cnn.com"); $pick=$sites[mt_rand(0,count($sites)-1)]; PHP: Followed up with: <input type="text" name="txtSomething" value="<?php echo $pick; ?>" /> HTML:
Yeah, basically that is correct. But I want to apply it to several different documents, so I will need to save the variable into a different PHP file, and include it into the form somehow. Thanks a lot, BP
Put tandac's code in a common.php file in a function called GetRandomSite (make sure to type "return $pick" as the last line of the function). Then include that file in all your pages. When you need a random site, just type echo GetRandomSite()