norbi35 Posted September 13, 2011 Share Posted September 13, 2011 Hello. Assuming that I have two variables: $exURL=@$HTTP_REFERER; $goodURL = 'http://www.SomeSite/login/'; How can I check if the two URLs match each other? Regards Quote Link to comment https://forums.phpfreaks.com/topic/247042-compare-two-urls-newby-to-php/ Share on other sites More sharing options...
AyKay47 Posted September 13, 2011 Share Posted September 13, 2011 with a comparison statement.. $exURL=$_SERVER['HTTP_REFERER']; $goodURL = 'http://www.SomeSite/login/'; if($exURL == $goodURL){ // URL's match }else{ // they don't } Quote Link to comment https://forums.phpfreaks.com/topic/247042-compare-two-urls-newby-to-php/#findComment-1268697 Share on other sites More sharing options...
Pikachu2000 Posted September 13, 2011 Share Posted September 13, 2011 Remember, == is case sensitive. If case doesn't matter, use strcasecmp or convert both to the same case before comparing them. Quote Link to comment https://forums.phpfreaks.com/topic/247042-compare-two-urls-newby-to-php/#findComment-1268704 Share on other sites More sharing options...
AyKay47 Posted September 13, 2011 Share Posted September 13, 2011 Remember, == is case sensitive. If case doesn't matter, use strcasecmp or convert both to the same case before comparing them. good point, that would be a good precautionary measure to take here.. so the code would look something like this OP $exURL=$_SERVER['HTTP_REFERER']; $goodURL = 'http://www.SomeSite/login/'; if(strcasecmp($exURL, $goodURL) == 0){ // URL's match }else{ // they don't } Quote Link to comment https://forums.phpfreaks.com/topic/247042-compare-two-urls-newby-to-php/#findComment-1268725 Share on other sites More sharing options...
norbi35 Posted September 13, 2011 Author Share Posted September 13, 2011 Thanks for the replies. These are rights methods. But I've noticed that $_SERVER['HTTP_REFERER']; is not "recognized" properly. I've made the following tests: case1: $exURL = 'http://www.SomeSite/login/'; $goodURL = 'http://www.SomeSite/login/'; your methods works fine case2: $exURL = $exURL=$_SERVER['HTTP_REFERER']; $goodURL = 'http://www.SomeSite/login/'; not working I've checked $exURL with echo(); : echo($exURL); // output: http://www.SomeSite/login/ Where is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/247042-compare-two-urls-newby-to-php/#findComment-1268755 Share on other sites More sharing options...
Pikachu2000 Posted September 13, 2011 Share Posted September 13, 2011 In short, you can't rely on that variable to be correct, or even present all the time. The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. Maybe if you explain what you're trying to do, someone can help you come up with a better way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/247042-compare-two-urls-newby-to-php/#findComment-1268757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.