blob: b43581082bd40c5851784ef24e4ace01d141c255 [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
#
#
#*****************************************************************************
function showErrorPage() {
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php");
$App = new App(); $Nav = new Nav(); $Menu = new Menu();
$html = '<div id="maincontent">
<div id="midcolumn">
<h1>ERROR</h1>
<p> THERE WAS AN ERROR
</p>
<hr class="clearer" />
</div>
</div>';
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html);
}
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: /");
showErrorPage();
}
# 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: /");
showErrorPage();
}
$dbc_RW->disconnect(); # disconnects all pending DB connections
$rs = null;
$dbh_RW = null;
$dbc_RW = null;
?>