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:
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:
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.)
What happens if you use
rawurldecode($lp)? I’ve tested in Windows 7 in IE7-10 and it works fine for me (both ways). Strange!
Check the URL you’re being redirected to in IE, what’s the address bar say?
To prevent problems with header redirects I usually use ob_start(); and ob_flush();
<?php ob_start(); //at the top of the page// header( $location ) ; ob_flush(); ?>
Maybe you have output buffering on the server. Output buffering can get the header out because of the buffer (as you know, the headers should be sent first).
Hope it could be the problem