Home     Articles & Projects     Products & Web Services     Forum

Exit Link Conditional Statement

Hi
Is PHP able to check what url a site visitor goes on exit and then perform a conditional action based on that url that they are going to.

So for example if a visitor goes from my site to siteB, is there a php function that would recognise that a visitor was going to a certain url from my site and do something if that were true, but do nothing if false. I want something that recognises the goto exit url, rather than whether they click on a certain link, as some links I can not edit, but would still like to do something if the url of that link were to go to a certain place, but nothing if not.

Basically I am wondering whether php includes a function that checks the url a visitor is going to from my site, so that I can write a conditional script if they do that.

Hi Clare, If they are links

Hi Clare,

If they are links that you have no control over there is no straight forward way to achieve this i'm afraid. Even links that you are creating; the conditional action (I presume logging or sending an alert email, something like that) would ordinarily require the use of a tracking script such as the universal redirection script described in this thread:

http://www.davidmorison.com/node/18

Your conditional code could then be patched in to the jumplib_getURL function as follows:

  function jumplib_getURL($id)
  {
    global $jumplib_connection;
    $sql = "SELECT url FROM links WHERE id='".mysql_escape_string($id)."'";
    $result = mysql_query($sql,$jumplib_connection);
    $link = mysql_fetch_assoc($result);
    if ($link["url"]=="http://www.example.com/")
    {
      // conditional action for www.example.com here
    }
    if ($link["url"]=="http://www.example.net/")
    {
      // conditional action for www.example.net here
    }
    return $link["url"];
  }

The only alternative I can think of would some complex JavaScript to detect a click on a link leaving the page and to perform an AJAX style action in order to invoke the alert back to your server - that of course relies on being a) possible and b) the client having JavaScript enabled so would not be 100% guaranteed by any means...

Cheers!
David.