Forum Moderators: coopster
Header("Refresh: 2;$url"); and Header("Location: $url"); with particular reference to how the referring domain looks/ is handle by the browser? I'm trying to understand the mechanics of tracking script I'm using: [webmasterworld.com...]
[edited by: encyclo at 4:53 pm (utc) on April 24, 2007]
[edit reason] fixed thread link [/edit]
- browser on example.com/page1.html
- Header("Refresh: 2;example.com/page2.html") sent to browser
- browser waits 2 seconds, redirects to example.com/page2.html, and example.com/page2.html shown in the browser URL area
- browser on example.com/page1.html
- Header("Location: example.com/page2.html
") sent to browser
- browser redirects to example.com/page2.html, and example.com/page2.html shown in the browser URL area
Difference may be in the http status code.
Seems like Header->Location send 302, and i suspect Refresh sends another http status.
This may be more important to crawlers than regular surfers.
Again, this is only my opinion, never tried/tested it.
Refresh isn't officially part of HTTP 1.1 and is usually used in HTML:
<META HTTP-EQUIV="Refresh" CONTENT="2; URL=http://host/path">
Refresh, however, is only supported as a header in Internet Explorer and Netscape, I believe. Therefore you will run into some trouble there. If you want to redirect somewhere, use Location.
My only problem with Location is that it appears to work too quickly and doesn't allow my Javascript tracking a chance to call it's functions.
Here is my code:
<?php
// GET PARAMS
$pid=$_GET['pid'];
$aid=$_GET['aid'];
$sid=$_GET['sid'];
$url=$_GET['url'];
if (strlen($sid) < 1){
$sid = 'organic';
}
// BUILD URL
$url = "http://www.example.net/click-$pid-$aid?sid=$sid&url=$url";
// PRINT
echo '<p>Loading...</p>';
echo '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">';
echo '</script>';
echo '<script type="text/javascript">';
echo '_uacct = "UA-#*$!#*$!X-X";';
echo 'urchinTracker("/tracking/");';
echo '</script>';
// REDIRECT TO URL
Header("Location: $url");
exit;
?>
Is it possible to use 'Location' redirects and keep Javascript tracking code working?
[edited by: eelixduppy at 8:10 pm (utc) on April 24, 2007]
[edit reason] exemplified [/edit]
document.location.href = "http://www.example.com";
This, I feel, will be your best bet in terms of redirecting the page because you cannot change the headers. You can, as you have suggested, use a REFRESH, but I'd use a meta refresh and not set the header. Both the javascript and the meta refresh have disadvantages as both of them can be disabled.