Check how user accessed file/script?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
st89
Forum Newbie
Posts: 17
Joined: Sat Nov 28, 2009 5:42 pm

Check how user accessed file/script?

Post 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
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Check how user accessed file/script?

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Check how user accessed file/script?

Post by josh »

st89
Forum Newbie
Posts: 17
Joined: Sat Nov 28, 2009 5:42 pm

Re: Check how user accessed file/script?

Post by st89 »

Post Reply