Hi, I have ran into a problem with a script I am using that shows content to a visitor based upon their browser referer. Here is the relevant portion of the script: <?php $allowed_referers[0] = "allowedwebsite.com"; $ok_mode = 0; if((in_array(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_HOST), $allowed_referers) && $_SERVER['HTTP_REFERER'] != "") || $ok_mode) { } ?> PHP: It works fine until I want to add additional allowed referers and that is where I encounter a problem. I would like to either add the list (which includes about 15 allowed referers) into the script or add a function that will retrieve the allowed referers from a text document. Any help would be greatly appreciated.
$allowed_referers[] = 'address.com'; PHP: Just use this line inside a loop or anything, php will automatically append the item to the array.
I appreciate your response but could you please use your code in an example with the code I posted? One more thing is that the script must keep the 0 in brackets as shown here $allowed_referers[0] PHP: since it designates whether it is in ok_mode (which is setup mode by the way). Again I appreciate any help in this matter.
No you can't. Keeping the 0 in bracket will replace the array value of item at index 0, so your array is forever having only 1 item. in my previous post i assumed you know how to do a loop. So forget it now. Here's how without using a loop, add manually into your code. Method 1: $allowed_referers[0] = "allowedwebsite.com"; $allowed_referers[1] = "allowedwebsite1.com"; $allowed_referers[2] = "allowedwebsite2.com"; ..... PHP: Method 2: $allowed_referers = array("allowedwebsite2.com" , "allowedwebsite1.com", "allowedwebsite2.com", ); PHP: Method 3: $allowed_referers[0] = "allowedwebsite.com"; $allowed_referers[] = "allowedwebsite1.com"; $allowed_referers[] = "allowedwebsite2.com"; ..... PHP: All 3 methods works the same.
Thanks ads2help. The first and third examples you provided work perfectly. For some reason the second example will not recognize the referers at all. This is the one I had been trying to get working before I made a post here. Again I appreciate you taking the time to help me figure this out.