Re: check if website has www. in front of domain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



    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); } ?>

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux