It’s handy to force users to view your website from only one domain, e.g www.example.com over example.com especially when dealing with sessions which are normally not domain specific. Rather than messing with server & cookie settings to try and get sessions to work across domain it is a lot easier to just force them on to one or the other.

It is also important to maintain the original uri they are requesting, in fact this is very easy to do. Take the below code which forces users to www.example.com over example.com

1
define('VALID_DOMAIN', 'www.example.com');
2
3
if(defined(VALID_DOMAIN) && VALID_DOMAIN !== null && $_SERVER['SERVER_NAME'] != VALID_DOMAIN) {
4
      header('location: http://'.VALID_DOMAIN.$_SERVER['REQUEST_URI']);
5
      exit;
6
}

Simple and effective.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2014 Altroleet Suffusion theme by Sayontan Sinha