hello there, this is my command <?php $allowed_refferer = array( 'http://www.google.com', 'http://www.yahoo.com' ); if (in_array($_SERVER['HTTP_REFERER'], $allowed_refferer)) { echo 'a'; } else { echo 'b'; } ?> PHP: i have one problem hope someone can help me with this... if the refferer is http://www.google.com is show me echo a but if the refferer is http://www.google.com/search... is not working anymore ... how i can make this work ? i want to use array becouse is more easy to add the links becouse before i use preg_match ...
Hmm I don't get it what's the problem. If the referrer is from http://www.google.com/search then why not just include it in the array? Otherwise, use preg_match <?php $allowed_refferer = array( 'http://www.google.com', 'http://www.yahoo.com', 'http://www.google.com/search' ); if (in_array($_SERVER['HTTP_REFERER'], $allowed_refferer)) { echo 'a'; } else { echo 'b'; } ?> PHP:
Would be easier to do it by host rather than URL: if( isset( $_SERVER['HTTP_REFERER'] ) ) { $Referer = parse_url( $_SERVER['HTTP_REFERER'] ); $allowed_refferer = array( 'google.com', 'yahoo.com' ); if (in_array( $Referer['host'] , $allowed_refferer)) { echo 'a'; } else { echo 'b'; } } PHP: