blob: 0c2fc81ba1e9fd1e65f069dfa51ff295f46de8c9 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2007 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Denis Roy (Eclipse Foundation)- initial implementation
*******************************************************************************/
#*****************************************************************************
#
# redirector.php
#
# Author: Denis Roy
# Date: 2007-09-07
#
# Description: redirector for campaign URL tracking
#
#
#*****************************************************************************
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php";
$App = new App();
# get the incoming parameters
$_TAG = $App->getHTTPParameter("tag", "GET");
if(strlen($_TAG) < 1) {
# error
header("Location: /");
}
# strip potentially bad characters from file
$_TAG = preg_replace('/["\'?%$#@!;*&]/i', '', $_TAG);
# Connect to databases
$dbc_RW = new DBConnectionRW();
$dbh_RW = $dbc_RW->connect();
$SQL = "SELECT TargetUrl FROM Campaigns WHERE CampaignKey = " . $App->returnQuotedString($_TAG) . " AND DateExpires > CURDATE()";
$rs = mysql_query($SQL, $dbh_RW);
if($myrow = mysql_fetch_assoc($rs)) {
# redirect the browser now
header("Location: " . $myrow['TargetUrl']);
# track the click
# Do a reverse lookup on the client IP
$client_hostname = @gethostbyaddr($_SERVER['REMOTE_ADDR']) ;
$SQL = "INSERT INTO CampaignClicks (
ClickID,
CampaignKey,
SubKey,
HostName,
TimeClicked) VALUES (
NULL,
" . $App->returnQuotedString($_TAG) . ",
NULL,
" . $App->returnQuotedString($client_hostname) . ",
NOW())";
mysql_query($SQL, $dbh_RW);
}
else {
# error finding Campaign
header("Location: /");
}
$dbc_RW->disconnect(); # disconnects all pending DB connections
$rs = null;
$dbh_RW = null;
$dbc_RW = null;
?>