tqla Posted January 14, 2009 Share Posted January 14, 2009 I am trying to do a preg_match to see if the HTTP_REFERER is from within my domain or from an external link. $site_url = http://(my website url is here); if(isset ($HTTP_REFERER)) { $ref = $HTTP_REFERER; if (preg_match($site_url, $ref)) { echo "match"; } else { echo "no match found"; } } But I get this error and "no match" when it should be a match in my test: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash on line 6 What am I doing wrong? ??? Link to comment https://forums.phpfreaks.com/topic/140872-solved-preg_match-help/ Share on other sites More sharing options...
lordphate Posted January 14, 2009 Share Posted January 14, 2009 you will need to only sear for the www.domain.com, not http:// as you will usually have a / in the end of referrers Link to comment https://forums.phpfreaks.com/topic/140872-solved-preg_match-help/#findComment-737340 Share on other sites More sharing options...
Mark Baker Posted January 14, 2009 Share Posted January 14, 2009 What am I doing wrong? ???It looks as though you're trying to use preg_match() as though its syntax was the same as substr(). Why not simply test your domain against parse_url($HTTP_REFERER,PHP_URL_HOST) Link to comment https://forums.phpfreaks.com/topic/140872-solved-preg_match-help/#findComment-737343 Share on other sites More sharing options...
tqla Posted January 15, 2009 Author Share Posted January 15, 2009 ah ha. thanks lordphate and Mark Baker. I get it now. <?php if(isset ($HTTP_REFERER)) { if ( parse_url($HTTP_REFERER,PHP_URL_HOST) ) { echo "match"; } else { echo "no match found"; } } ?> Link to comment https://forums.phpfreaks.com/topic/140872-solved-preg_match-help/#findComment-737372 Share on other sites More sharing options...
tqla Posted January 15, 2009 Author Share Posted January 15, 2009 actually, the if statement would need to compare to something for this to work. <?php if(isset ($HTTP_REFERER) == $url ) { if ( parse_url($HTTP_REFERER,PHP_URL_HOST) ) { echo "match"; } else { echo "no match found"; } } ?> Link to comment https://forums.phpfreaks.com/topic/140872-solved-preg_match-help/#findComment-737401 Share on other sites More sharing options...
tqla Posted January 15, 2009 Author Share Posted January 15, 2009 Oops I mean like this!! The comparison should be in the 'if' statement. Sheece. Tired. <?php if(isset ($HTTP_REFERER)) { if ( parse_url($HTTP_REFERER,PHP_URL_HOST) == $url ) { echo "match"; } else { echo "no match found"; } } ?> Link to comment https://forums.phpfreaks.com/topic/140872-solved-preg_match-help/#findComment-737408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.