Forum Moderators: coopster

Message Too Old, No Replies

Loading cookies code and then redirecting

How to do seemlessly

         

planbeta

9:57 am on Jun 30, 2003 (gmt 0)

10+ Year Member



Hello!

I have a site I am developing that when a certain link is clicked it goes to a script called out.php

What this does is display a message saying, 'thanks for visiting' and in the background it loads some tracking code in an 'img src' tag then 2 seconds later redirects to a predifined url ie.

out.php?trackcode=http://www.trackingcode.com&url=http://www.redirecthere.com

This works fine but I have seen a site that does exactly the same as the above except you never see the 'out' script page, and when you click on a link it looks like a seemless redirect to the 'url=' yet still manages to load the trackcode.

I have spent all weekend trying to figure this out, but it has me flummoxed.

Anyone have any ideas how this might be done?

Thanks

Chris

dmorison

10:21 am on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can dump a cookie and serve a 301 redirect in the same response - isn't that all you want to do...

<?php

setcookie("some_name","some_value",strtotime("2020-01-01"),"",".yourdomain.com");

header('HTTP/1.1 301 Moved Permanently');

header("Location: [example.com...]

?>

planbeta

10:37 am on Jun 30, 2003 (gmt 0)

10+ Year Member



Thanks for the suggestion, but not quite what I need.

The cookies aren't set in the traditional sense, they are set from an url which I have been loading in an image source tag ie.

<img src="http://www.trackurl.com/?order=1" width="1" height="1">

So what I have been doing, from my out.php script, is load this code first then using a 2 second time delayed header redirect go to the url, while the page says 'thanks for visiting'.

I would like to cut this page out and make all this seem invisible to the user. I am not sure how the other site I have seen has done this?

Cheers anyway

Chris

dmorison

10:56 am on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok - so you have no control over the site that serves the web bug?

planbeta

11:26 am on Jun 30, 2003 (gmt 0)

10+ Year Member



Unfortunately not, that would make things considerabley easier. :¦

Cheers

Chris

vincevincevince

4:01 pm on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how about the amazing frames? make two frames, one height of 100%, other height of 0, in the first load their destination page, in the second load your image?

it's not cute, but it would work

OR, i'm pretty sure you can get javascript to load the image onClick(), wait a sec for it to load, then do the redirect?

still not cute, but it would work

OR, add your image to their destination page (fopen their destination url, append the html for your image to the end and the correct base href, then echo it)

dmorison

5:28 pm on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just did a quick experiment, and onload() is valid for an <img> tag; - and better still doesn't fire until the image has, well, loaded :) This is in IE6 - you'd have to check compatibility, and of course provide a <noscript> option so that users without Javascript can click to be redirected. You'll still drop the tracking cookie.


<script type='text/javascript'>

function DoRedirect()
{
window.location = 'http://www.example.com/';
}

</script>

<img onload='javascript:DoRedirect()' src="http://www.trackurl.com/?order=1" width="1" height="1">

planbeta

9:28 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



Thanks dmorison, will give a try - looks good.

Cheers

Chris