Re: check if website has www. in front of domain
| From: | Daniel Brown | Date: | Fri, 15 Feb 2008 20:47:11 +0000 |
| Subject: | Re: check if website has www. in front of domain | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269381@lists.php.net to get a copy of this message | ||
Please don't start a new thread for every time you change a bit of
your code. It messes up the archives and fills people's inboxes.
In any case, change the following two functions as shown. You
were setting $this->WWW to False (with only one = operator), and you
should also use $_SERVER['HTTP_HOST'] as that's the domain that was
accessed. If you use $_SERVER['SERVER_NAME'] it uses the
server-configured name. If the server is configured as www.blah.com
it will redirect to www.www.blah.com. Conversely, if
$_SERVER['SERVER_NAME'] == blah.com then the expression will always
evaluate to true, regardless of how it was accessed.
// Check if site is preceeded by 'WWW'
public function checkWWW() {
$myDomain = $_SERVER['HTTP_HOST'];
$FindWWW = 'www.';
$POS = strpos($myDomain, $FindWWW);
if ($POS === 1) {
$this->WWW = true;
} else {
$this->WWW = false;
}
}
// Redirect to WWW
public function WWWRedirect() {
if ($this->WWW == false) {
$redir = "Location:
http://www.".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header($redir);
}
}
--
</Dan>
Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>