Solved How do I fix my redirect loop?

Microsoft / Vista
November 15, 2010 at 18:15:43
Specs: Windows Vista, 2GB
Okay, so I have this website and it only looks good in Chrome and Safari, so I have it set that on the page load, it will redirect to (for the purposes of this example) Google if it detects IE or any other browser, but I also have it set so that it will redirect to the same page if it detects Chrome or Safari, but with it redirecting to the same page, it creates a redirect loop. So can you look at my code and see if you can find a fix for it. Thanks, here's my code:

<?php
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

// Identify the browser. Check Safari first in case of spoof. Let Google Chrome be identified as Safari.
if (preg_match('/webkit/', $userAgent)) {
Header("Location: #");
}
else {
Header("Location: http://www.google.com");
}
?>

And if you need more information, then just ask. Thank you.


See More: How do I fix my redirect loop?

Report •


#1
November 15, 2010 at 21:04:19
could you change the redirect to a page that is identical to your # but doesn't redirect?

Report •

#2
November 15, 2010 at 21:16:38
I could, but that would be really tedious because then I would have to do that with every page of my site. I have it redirect to a warning page saying that things could look weird, out of place, etc. once per every session. So I was kind of thinking of trying to figure out a way that instead of
if browser = Chrome/Safari, goto # and
if not goto warning.php
it would just be something like
if browser does not = Chrome/Safari, then goto warning.php

Report •

#3
November 15, 2010 at 21:19:01
✔ Best Answer
what about making your warning page your # and then automatically redirect to the actual main page if the agent matches webkit chrome/safari

Report •

Related Solutions

#4
November 15, 2010 at 21:25:30
That, my friend, is an excellent idea! You're a genius! Thank you.

Report •

#5
November 15, 2010 at 21:27:33
just glad I could help... :)

Report •

#6
November 15, 2010 at 21:28:57
(added bonus helping with a site that doesn't render in IE)

:)


Report •


Ask Question