Page 1 of 1

Check how user accessed file/script?

Posted: Sat Nov 28, 2009 5:59 pm
by st89
Is there a way in PHP to check how a user accessed a PHP file?

For example, say a web user types in (directly visits) http://host.domain/embeddedmailingscript.php rather than accessing the PHP through a form (e.g. POST to embeddedmailingscript.php). Is it possible to block the former whilst still allowing the latter?

What i'm trying to achieve (in pseudo-pseudocode):

Code: Select all

<?php
if ($userDirectlyVisits == true)
{
  header("Location: home.php"); //user returned to default homepage
}
else
{
  // Code completed as normal e.g. $_POST[] input taken and manipulated
}
?>
Thanks in advance for any help/tips/pointers :D

Re: Check how user accessed file/script?

Posted: Sat Nov 28, 2009 6:01 pm
by iankent
Try looking at $_SERVER['HTTP_REFERER'] - but its no guarantee, its up to the browser whether or not the HTTP_REFERER gets sent

Re: Check how user accessed file/script?

Posted: Sun Nov 29, 2009 1:33 am
by josh

Re: Check how user accessed file/script?

Posted: Sun Nov 29, 2009 12:05 pm
by st89