Reputation: 7602
I have to check that the URL does not contains a string.
$url = $_SERVER['HTTP_REFERER'];
$match1 = "http://myapp.com";
$match2 = "http://www.myapp.com";
I want to check that the value in $url
does not contain either $match1
and $match2
. How do I do this?
Upvotes: 0
Views: 277
Reputation: 36
In my opinion,matching the string or matching a pattern which contains multiple url forms is what you need think. such as :
considering all of the situations!
Note:HTTP_REFERER can be forged.
so,you may validate it like this:
if ($url = filter_var($url, FILTER_VALIDATE_URL)){
if(!in_array( parse_url($url,PHP_URL_HOST), array('myapp.com','www.myapp.com',...) )){
// do something
}
}
Upvotes: 1
Reputation: 86
Be aware that the referrer string is not always set (browsers may decided not to send it) so don't rely on it for important functionality.
Upvotes: 1
Reputation: 68476
Make use of strpos()
in PHP
<?php
$yoururlarray=['somewebsite.com','somewebsite2.com'];
$urls=implode(',',$yoururlarray);
if(strpos($_SERVER['HTTP_REFERER'],$urls)!==false)
{
// Found a match so write the ignore code here as you want !
}
Upvotes: 1