$words = array('word', 'another', 'third', 'etc');
$regex = '/(' . implode('|', $words) . ')/'; // '/(word|another|third|etc)/'
if (preg_match($regex, $_SERVER['HTTP_REFERER']) === 1) {
// restriced word found
} else {
// restricted word not found, do stuff
}
the REFERER is sent by the client's browser as part of the HTTP protocol, and is therefore unreliable. It might not be there, it might be forged, you just can't trust it if it's for security reasons.
PHP:$words = array('word', 'another', 'third', 'etc'); $regex = '/(' . implode('|', $words) . ')/'; // '/(word|another|third|etc)/' if (preg_match($regex, $_SERVER['HTTP_REFERER']) === 1) { // restriced word found } else { // restricted word not found, do stuff }
Just keep in mind that
the REFERER is sent by the client's browser as part of the HTTP protocol, and is therefore unreliable. It might not be there, it might be forged, you just can't trust it if it's for security reasons.
<?php $words = array('word', 'another', 'third', 'etc');
$regex = '/(' . implode('|', $words) . ')/';
if (preg_match($regex, $_SERVER['HTTP_REFERER']) === 1) {
// restriced word found, do nothing
} else {
// restricted word not found, add that JS
?>
<script type="text/javascript" src="yourscript.js"></script>
<?php
} ?>