Forum Moderators: coopster
If file1.php was not referred by file of same domain (www.example.com) then include php from this file2.php.
I basically would like to print out a message box with html and stuff if the referred isn't from my own domain (so I can have the user specify some quick preferences).
Reffer code is this....
$_SERVER['HTTP_REFERER']
So here I am trying to put this together but I'm short on some of the sytax! :-D
<?php
if $_SERVER['HTTP_REFERER'] ....
How do I say "Does not start with!" Lets say I want to say if the referrer does not start with "http://www.example.com" THEN...
You specific case could be handled like this, if your domain was example.com
//throwing referer in an array for clarity
$ref = $_SERVER['HTTP_REFERER'];
if(preg_match('/^example\.com/', $ref) ){
//do matched stuff
}
else{
//do unmatched stuff
}
The important part is the /^example\.com/. The two forward slashes say (more or less) the text in-between here is our regular expressions. The ^ says "any string starting with the following. The \. is needed because the period is a special character in regular expressions, and needs to be escaped (like double quotes in strings.
If you've followed this so far, you probably realize the above will only match example.com, and NOT www.example.com. To handle that, you could do it the obvious way with two calls to preg_match
if(preg_match('/^example\.com/', $ref) ¦¦ preg_match('/^www\.example\.com/', $ref)){
//do matched stuff
}
else{
//do unmatched stuff
}
if(preg_match('/^(www\.example¦example)\.com/', $ref) ){
//do matched stuff
}
else{
//do unmatched stuff
}