Today is Sunday
September 5, 2010

Search Results Tag: domain name

June 22, 2010

PHP my domain name

by Chris — Categories: Coding, PHP — Tags: , No Comments

Need to find your domain name for a script? Maybe you want to ensure something thats going to run is being run on your site and your site alone. In concept for example trying to protect your script from XSS attacks, say in a case where your using AJAX to POST/GET JSON requests (but this is only a small example of why you might want to implement something like this).

<?php
$mydomain = $_SERVER['HTTP_HOST'];
$mydomain = str_replace('www.''', $mydomain);

if($mydomain == "your-domain-name.com"){
/*your domain found, script to run*/
}else{
/*your domain NOT found, script to run*/
}
?>

Now some people will most likely argue that you should use

$_SERVER['SERVER_NAME']

instead of

$_SERVER['HTTP_HOST']

And this is plausible as they do pretty much the same exact thing. However the key difference is how one reads off the server versus the other, I would go in to the differences but Chris Shiflett puts it together in a nice summary in his article SERVER_NAME Versus HTTP_HOST and backs it up with various tests and other articles he has found on the subject.

© 2010 Monkey Tooth Productions All rights reserved - Wallow theme by TwoBeers Crew - Powered by WordPress - Have fun!