Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect randomly failing in IE 8 and older

On our adserver, we use the following simple PHP script to redirect to the landing page of the ad:

<?php
$lp=array_key_exists('lp',$_REQUEST)?trim($_REQUEST['lp']):"";
$location = sprintf('Location: %s', $lp ) ;
header( $location ) ;
?>

The script takes its lp parameter and redirects to that URL. The purpose is so that we can scan our access log to track clickthroughs (the URL also includes an id parameter, which the script ignores).

We have one customer (that I know of so far) where this isn't working consistently, but only in IE 8 and older. The URL with the problem is:

http://webutil.bridgebase.com/v2/ad_lp.php?id=340&lp=http%3A%2F%2Ftravelinsingles.com%2Fhome.htm

This should redirect to http://travelinsingles.com/home.htm, but sometimes it goes to http://webutil.bridgebase.com/home.htm (which doesn't exist). It always seems to happen on the first click on the ad; sometimes subsequent clicks follow the redirect correctly, sometimes they continue to go to the bad URL.

I performed a packet capture on our webserver, it looks like we're sending the correct header:

HTTP/1.1 302 Moved Temporarily
Server: nginx/1.2.1
Date: Thu, 06 Jun 2013 01:39:12 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/5.4.15-1
Location: http://travelinsingles.com/home.htm

I captured both on a failing and successful redirect, and the headers were identical except for the Date.

I'm using a Mac, so I use BrowserStack to test IE, which limits my debugging ability at the client end. Does anyone know what could be causing this, and if there's something we can do to work around it?

I reproduced the problem with BrowserStack's screenshots feature:

http://www.browserstack.com/screenshots/3659c3b992a1738594d2fd370caef2852fecb3fa

like image 704
Barmar Avatar asked Jun 06 '13 02:06

Barmar


1 Answers

Does adding exit or die(); to the end of your PHP make a difference?

Sometimes HTTP clients don't like it when a redirect header is sent while content still exists in the body (even if it's empty content: spaces, line returns, etc.)

like image 176
Jeff Sisson Avatar answered Oct 25 '22 12:10

Jeff Sisson