Re: check if website has www. in front of domain
| From: | Daniel Brown | Date: | Fri, 15 Feb 2008 21:08:42 +0000 |
| Subject: | Re: check if website has www. in front of domain | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269389@lists.php.net to get a copy of this message | ||
On Fri, Feb 15, 2008 at 3:55 PM, nihilism machine
<nihilismmachine@gmail.com> wrote:
> Still doing the old behavior (www.www.domain.com)
This code works. You can see it in action at
http://www.pilotpig.net/code-library/checkwww.php
and see the source
at http://www.pilotpig.net/code-library/source.php?f=checkwww.php.
<?php
class URL {
// Public Variables
public $HTTPS;
public $ServerName;
public $WWW;
// Public Functions
public function __construct() {
$this->checkWWW();
}
// Check if site is preceeded by 'WWW'
public function checkWWW() {
if(preg_match('/^www\./Ui',$_SERVER['HTTP_HOST'])) {
$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);
}
}
}
$myURL = new URL();
$myURL->WWWRedirect();
?>
--
</Dan>
Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>