Jump to content

compare two URLs (newby to PHP)


norbi35

Recommended Posts

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
}

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?

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.