Thanks, Twey. Anyways, what do you think about my latest approach vs. the one right before it:
vs:PHP Code:<?php
$theHost = $_SERVER['HTTP_HOST'];
$theBack = $_SERVER['HTTP_REFERER'];
$theBParse = parse_url($theBack);
if ($theBParse['host'] == $theHost)
echo $theBack; // or do whatever if referrer is from the same domain
else
echo 'other domain'; // or do whatever if the referrer is from another domain
?>
I also had another approach using substr() and strlen(), and an equality comparison between:PHP Code:<?php
$thePat = '^http://' . $_SERVER['HTTP_HOST'];
$theBack = $_SERVER['HTTP_REFERER'];
if (ereg($thePat, $theBack))
echo $theBack;
else
echo 'other domain';
?>
and and a substr of equal length counting from the beginning of:PHP Code:'http://' . $_SERVER['HTTP_HOST']
But I think the best is the one at the top of this post. I'm still a great novice at PHP, but I think it combines maximum accuracy with with the lowest possible overhead for that accuracy.PHP Code:$_SERVER['HTTP_REFERER']
Unfortunately, the server I'm working on does not support the component parameter of parse_url(), otherwise it could have been even simpler, or at least more direct looking.



Reply With Quote

So long as you bear in mind that it may be nonsensical or non-existant, and always provide an alternative means of accessing anything important, you'll be fine.
). It simply wouldn't be useful to duplicate that.
. A different filter would need to be applied if you intended the input to be used as part of an SQL query or a shell command, for example.
Bookmarks