A little tutorial that some might find very use full.
Every got a page set up so it look prefect and then you have a look at it in Internet Explorer (here after know as IE) and it looks terrible? And then thought if only I could add some code that only shows up in IE. Well, you can!!
The first thing you need to do is test of your server supports php, this is easy. (frihost dose so you could skip this part.)
Copy that into your text editor and save it as info.php upload if to your server and open it. If it works you will get a page that tells you all about the the php set up on your server, if not you get a blank page.
Well now we have to turn your pages into php, that is easy just change the end from .html or .htm to .php
Ok great so now we have code that the server only sends out to the user if they are useing IE (php is server side programing, what gets sent to the user is HTML). If you look into thing a bit more you will soon see you have created another problem! Opera users see the text too! So we have fix that, here is the code
Fine you say, my problem is not the HTML code but my css.
Well you have two options. First add a some css directly into the head of the page like this
The other option is to have a css file for IE and another css file for every one else. Like this
Ok find but now you want to do it to browsers other than IE. If you looked at the code you might have noted that for Opera there is 'Opera' in the code and for Internet Explorer 'MSIE' well that is what you have to change here is a table of posible options (there might be others but these are the most common).
Have fun!
Oh and did I tell you that
works just as well, you just can get the fanny effect with other browsers. :twisted: (I just had to leave that till last)
Every got a page set up so it look prefect and then you have a look at it in Internet Explorer (here after know as IE) and it looks terrible? And then thought if only I could add some code that only shows up in IE. Well, you can!!
The first thing you need to do is test of your server supports php, this is easy. (frihost dose so you could skip this part.)
| Code: |
| <?php phpinfo(); ?> |
Copy that into your text editor and save it as info.php upload if to your server and open it. If it works you will get a page that tells you all about the the php set up on your server, if not you get a blank page.
Well now we have to turn your pages into php, that is easy just change the end from .html or .htm to .php
| Code: |
| <?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { ?> The Text that you want anyone using IE to see, this can include HTML. <?php } ?> |
Ok great so now we have code that the server only sends out to the user if they are useing IE (php is server side programing, what gets sent to the user is HTML). If you look into thing a bit more you will soon see you have created another problem! Opera users see the text too! So we have fix that, here is the code
| Code: |
| <?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) { ?> This is were you put code that only Opera uses see, leave it black so they don't see anything that we only what to show up in IE. <?php } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { ?> Ok so this is were you put code that only IE users see and no one else. <?php } ?> |
Fine you say, my problem is not the HTML code but my css.
Well you have two options. First add a some css directly into the head of the page like this
| Code: |
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> <head> <title>Title</title> <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) { ?> Again we have to stop it working in Opera as well, so we leave here blank <?php } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { ?> <style> Your css code for IE only </style> <?php } ?> </head> |
The other option is to have a css file for IE and another css file for every one else. Like this
| Code: |
| <?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) { ?> <link rel="stylesheet" type="text/css" href="default.css" title="Default"> <-- again we have to give Opera something first, you will want to make this your default css file. <?php } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) { ?> <link rel="stylesheet" type="text/css" href="ie.css" title="Internet Explorer"> <-- this is the IE only css file. <?php } else { ?> <link rel="stylesheet" type="text/css" href="default.css" title="Default"> <-- This is for every other browser the works as it should. <?php } ?> |
Ok find but now you want to do it to browsers other than IE. If you looked at the code you might have noted that for Opera there is 'Opera' in the code and for Internet Explorer 'MSIE' well that is what you have to change here is a table of posible options (there might be others but these are the most common).
| Code: |
| MSIE = Internet Explorer
Opera = Opera Gecko = Mosilla Suite / SeaMonkey Firefox = FireFox Netscape = Netscape Konqueror = Konqueror Phoenix = Mozilla Phoenix Firebird = Mozilla Firebird Safari = Safari |
Have fun!
Oh and did I tell you that
| Code: |
| <!--[if IE]>The text that only Internet Explorer sees<![endif]--> |
