Skip to content
Advertisement

add another refer domain in HTTP_REFERER

$_SERVER['HTTP_REFERER'], "https://domain1.com/"))

How to add another domain https://domain2.com/ in this PHP code

Advertisement

Answer

Use in_array, but you should also parse out just the domain, as referer contains the complete URL, not just the domain.

Example (https://3v4l.org/o4MmW):

<?php

$_SERVER['HTTP_REFERER'] = 'http://example.com/foo/bar?baz=1';

//
if (in_array(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST), [
    //
    'example.com', 
    'www.example.com',
    //
    'domain1.com',
    'www.domain1.com',
    //
    'domain2.com',
    'www.domain2.com'
])) {
    echo 'In referer';
} else {
    echo 'Not in referer';
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement