[support] Cookie/Visit Tracking + Redirection

brew at theMode.com brew at theMode.com
Sat Mar 18 14:42:42 UTC 2006


George.......

> ** If anyone does have any further experiences, or even better, if
> there is a module that handles what I'm wanting to do more
> efficiently, please advise.

Here is the function that I use for redirection in PHP.  The part you
probably need is just the call to the header function, but I don't think
it would hurt to use it as is.  The first part is for session variables
when passed in the URL and the session_write_close might be neccessary if
any session variables were changed before the redirect.  There are also
some notes from people on php.net that say exit shouldn't be called after
the redirect, you should just make sure no other code executes afterward.

For instance:

if (some condition) {
   $page = 'webpage.php';
   relative_redirect($page);
} else {
   # a bunch of other code
}

# and then the main part of the code just ends with no exit.

Anyway, here's the function:

function relative_redirect ($relative_url) {
    # if SID exists add it to the url
    if (SID) {
        if ( strstr( $relative_url, '?')) {
            # then add it to existing get string
            $relative_url .= '&';
        } else {
            # else start a new get string
            $relative_url .= '?';
        }
        $relative_url .= strip_tags(SID);
    }
    session_write_close();
    header("Location: http://".$_SERVER['HTTP_HOST']
         .dirname($_SERVER['PHP_SELF'])
         .$relative_url);
}


brew

 ==========================================================================
                  Strange Brew   (brew at theMode.com)
  Check out my Stock Option Covered Call website  http://www.callpix.com
     and my Musician's Online Database Exchange http://www.TheMode.com
 ==========================================================================



More information about the support mailing list