Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Substitute a header.php for another header.php based on browser type?



6:39 pm on Oct 7, 2009 (gmt 0)

10+ Year Member


I'd like to be able to set up my site with a PHP script that swaps the header.php based on what browser the user has, so if a user is surfing via a mobile Safari browser (iPhone), it will swap the normal header.php with an alternative header.php more suitable for those browsers. Does this make sense?

Any help appreciated!


6:47 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

It would probably be better to have all code within the header.php script, and use if/else statements so different code is run depending on the browser (rather than different header.php files).
You can get the browser user agent with $_SERVER['HTTP_USER_AGENT'] and then use a regular expression to determine what type of browser it is and serve different code based on if the regular expression matches a browser type of IE, Firefox, etc...


6:55 pm on Oct 7, 2009 (gmt 0)

10+ Year Member

Hmm, that would save a lot of trouble, the only thing is I only have a rudimentary understanding of PHP so I'd need help on the proper code.

The only thing I need to change is to have an if/else statement determine the font size inside a small block. For normal browsers the font size is normal, but for the iPhone it needs to be several sizes smaller (xx-small).


Featured Threads

Hot Threads This Week

Hot Threads This Month