homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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

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


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)

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)

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).

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved