Forum Moderators: coopster

Message Too Old, No Replies

Preg Match issues

preg match referrer

         

chrissim

6:08 am on May 14, 2010 (gmt 0)

10+ Year Member



hi

i have this following code in my script but it still recorded my domain in my referrer list and i want my own site to be excluded in my hits list. Something wrong with these coding and does this code != 'www.mydomain.com' suppose to tell them not to be included anyway?


if (preg_match('/([^\.\/]+)\.([^\.\/]+\.[^\.\/]+)$/',$surl) != 'www.mydomain.com') {
$url = $surl;

Matthew1980

7:22 am on May 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there chrissim,

Ok, you want your site to be excluded, try this (not too sure on the regexp as it's not my strongsuite):-

//This will match every thing that isn't 'yoursite'.
$surl = "www.mydomain.com";

if (!preg_match('/([^\.\/]+)\.([^\.\/]+\.[^\.\/]+)$/',$surl) == 'www.mydomain.com'){
//not matched
echo "not matched";
}
else{
//matched
echo "matched";
}

Try that, I always find as doing it this route is a little more reliable.

Cheers,
MRb

chrissim

10:30 am on May 14, 2010 (gmt 0)

10+ Year Member



hey Matthew1980,

Thanks i give it a try but i have found out the script by applying ignore url array such as the code below
and it is very effective and works pretty well.


$ignoreurl = array( "http://mydomain.com", "http://otherdomain", "etc domain you have");
$ignore_url= false;
foreach( $ignoreurl as $ignore ) {
if( stristr( $_SERVER["HTTP_REFERER"], $ignore ) !== false ) {
$ignore_url = true;
break;
}
}

Matthew1980

11:03 am on May 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there chrissim,

Cool, glad your sorted out. I suspect as you are just wanting to ignore just those two url types as specified, so there is no need to make it a dynamic array. I was just thinking of the possibility of other instances that you haven't encountered yet. But as long as it is functional & does the job, great ;)

Cheers,
MRb