PHP referrer domain and subfile -
i have code:
$allowed_host = 'domain.com'; $host = parse_url($_server['http_referer'], php_url_host); if(substr($host, 0 - strlen($allowed_host)) == $allowed_host) { echo "ok"; } else { echo "not ok"; exit(); }
this code based on domain how can check domain , php file?
if referrer page: domain.com/fromok.php {echo "ok";} else {echo "not ok";}
your code give 'ok' if request host name ends 'domian.com'
, example if 'adomian.com'
. assume don't want it.
you can use
$allowed_host = 'domain.com'; $allowed_path = '/fromok.php'; $url_components = parse_url($_server['http_referer']); if((($url_components['host'] === $allowed_host) || (substr($url_components['host'], - (strlen($allowed_host) + 1) === '.' . $allowed_host)) && ($url_components['path'] === $allowed_path)) { echo "ok"; } else { echo "not ok"; exit(); }
Comments
Post a Comment