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');
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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]-->

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.