On Fri, Feb 15, 2008 at 3:55 PM, nihilism machine
<[EMAIL PROTECTED]> 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); } ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to