Jump to content

Conditional URL Ridirect (depending on user browser)


Monj87

Recommended Posts

Trying to set a condition in my header a few questions:

 

This code is close but gives me an error code and doesn't redirect.

 

1) Can anyone figure out how to make this work so that if user is in IE6 the url will redirect to the second URL?

2) I would put this in my header right? I can't figure out why this isn't working.

 

<?php
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
function str_present($str,$substr)
{	
$pos = strpos($str,$substr);
if($pos === false) {
return false;
}
else {
return true;
}
}
if (str_present($HTTP_USER_AGENT, "IE6"))
{
header('location: url1');
}else{
    header('location: url2');
}
?>

it's always a nice thing if you let others know what exact error you get.

Besides that if you are only targeting ie6, you might want to add a meta redirect with conditional comments like so:

<!--[if IE 6]>
<meta http-equiv="refresh" content="0; url=http://example.com/">
<![endif]-->

 

place it in the header

  • 2 weeks later...

THIS IS AWESOME.

 

Ive been searching everywhere though and how the heck would i replace "IE 6" with to do this with FireFox 2?

 

Could you point me in the right direction to find that out or let me know?

 

THANKS!!! IT WORKED AWESOME

type in google conditional comments first link or try:

http://www.quirksmode.org/css/condcom.html

 

Not sure what you want to use this for though. I only  use it to back up ie  7 and 6.

 

If you want a more complete thing use this:

http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

 

good luck!

 

eidt: and mark it solved ones your done

type in google conditional comments first link or try:

http://www.quirksmode.org/css/condcom.html

 

Not sure what you want to use this for though. I only  use it to back up ie  7 and 6.

 

If you want a more complete thing use this:

http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

 

good luck!

 

eidt: and mark it solved ones your done

 

did you read this??

Yes i read it. What i found in there was that FF is hard to create conditionals with. I really don't have time to do research looking a quick answer =) (thank you in advance)

 

Can anyone give me the answer?

 

HOW do i replace "IE6" with Fire Fox 2 in this code.  so that i can put it into a prefixed conditional statement like this.

 

<!--[if IE 6]>
<meta http-equiv="refresh" content="0; url=http://example.com/">
<![endif]-->

 

are you serious????

 

If you want a more complete thing use this:

http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

 

good luck!

 

did you click that? Are you seriously expecting that people here copy paste that stuff for you? and post it here so you don't have to do the effort?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.