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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -