<% // SendAdTo.htm ======================================================= FOR BANNER AND DISPLAY ADS // Usage: http://www.usawebadv.com/SendAdTo.htm?IDNo=00000&From=00000 // Usage: http://www.usawebadv.com/SendAdTo.htm?IDNo=<$cLinkNo>&From=<$cPageNo> // This is the main script that receives an Ad link request // from a USA Web directory visitor, locates the URL for // the link, records the request in the NewClix log, // and forwards the request to the Client's website. @session_start(); // Retrieve constants require("Tracker-XS.php"); // Retrieve Functions include_once "/home/usaweb/www/usawebadv.com/Master/_Ins/Functions.htm"; // ==================================================================== Get File information from the Server include "/home/usaweb/www/usawebadv.com/_Ins/Get-Server-Info.htm"; // Set variables $cErrMsg = ""; // ======================================================= GET IDNo if ((isset($_GET['IDNo'])) AND (!empty($_GET['IDNo']))){ $cLinkNo = $_GET['IDNo']; } else { $cLinkNo = '000000'; $cErrMsg .= "No Link-ID No. included in URL.\n"; } // ======================================================= GET From if ((isset($_GET['From'])) AND (!empty($_GET['From']))){ $cFromPageNo = $_GET['From']; if ((substr_count($cFromPageNo,'Life') > 0) OR (substr_count($cFromPageNo,'Living') > 0) OR (substr_count($cFromPageNo,'Guide') > 0)){ $cErrMsg .= "Bad From: " . $cFromPageNo . " Referrer: " . $_SERVER["HTTP_REFERER"] . "\n"; } } else { $cFromPageNo = "000000"; $cErrMsg .= "No Source-PageNo included in URL.\n"; } $cDateTime = date("Y-m-d H:i:s"); $cDate = substr($cDateTime, 0, 10); $cTime = substr($cDateTime, 11, 8); $cWebLink = ""; $cWebsite = ""; $lGo = FALSE; $cResponseCode = '200'; $cSQL = ""; if (($cLinkNo <> "000000") AND ($cLinkNo < '050000')){ // Open connection to database $rdBLink = mysql_connect($cHost, $cUser, $cPasscode); if (!$rdBLink){ $cErrMsg .= "Could not establish link with database.\n"; $cResponseCode = '503'; } else { // =================================================== Retrieve destination URL and Client information $lOkay = mysql_select_db($cdBName, $rdBLink); if (!$lOkay){ $cErrMsg .= "ClixTrax database not opened for Weblink selection.\n"; $cResponseCode = '503'; } else { if ($cFromPageNo != '000000'){ // =========================================== Find the SiteNo and Website Name $cSQL = "SELECT "; $cSQL .= "PageList.Website, "; $cSQL .= "SiteList.SiteNo "; $cSQL .= "FROM PageList "; $cSQL .= "LEFT JOIN SiteList ON PageList.Website=SiteList.Website "; $cSQL .= "WHERE PageList.PageNo='" . $cFromPageNo . "' "; $cSQL .= "AND SiteList.Main='T' "; // Run the SQL Query $aResult = mysql_query($cSQL, $rdBLink); if (!$aResult){ $cErrMsg .= "Could not run the PageList query.\n"; $cErrMsg .= mysql_error($rdBLink) . "\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; // ResponseCode not applicable because this data is not critical } else { if (mysql_num_rows($aResult) == 1){ // Retrieve the PageList Information $aRow = mysql_fetch_assoc($aResult); $cWebsite = $aRow['Website']; $cSiteNo = $aRow['SiteNo']; } elseif (mysql_num_rows($aResult) == 0){ $cErrMsg .= "No record of Page No. " . $cFromPageNo . " for SendAdTo.\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; // ResponseCode 404 not applicable because this data is not critical } elseif (mysql_num_rows($aResult) > 1){ $cErrMsg .= "More than one record for Page No. " . $cFromPageNo . " for SendAdTo.\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; // ResponseCode 404 not applicable because this data is not critical } } } // =========================================== Find the WebLink $cSQL = "SELECT "; $cSQL .= "LinkList.WebLink "; $cSQL .= "FROM LinkList "; $cSQL .= "WHERE LinkList.LinkNo='" . $cLinkNo . "' "; // Run the SQL Query $aResult = mysql_query($cSQL, $rdBLink); if (!$aResult){ $cErrMsg .= "Could not run the LinkList query.\n"; $cErrMsg .= mysql_error($rdBLink) . "\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; $cResponseCode = '503'; } else { if (mysql_num_rows($aResult) == 1){ // Retrieve the LinkList Information $aRow = mysql_fetch_assoc($aResult); $cWebLink = $aRow['WebLink']; $lGo = TRUE; } elseif (mysql_num_rows($aResult) == 0){ $cErrMsg .= "No record of Link No. " . $cLinkNo . ". for SendAdTo\n"; $cErrMsg .= mysql_error($rdBLink) . "\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; $cResponseCode = '410'; } elseif (mysql_num_rows($aResult) > 1){ $cErrMsg .= "More than one record for Link No. " . $cLinkNo . " for SendAdTo.\n"; $cErrMsg .= mysql_error($rdBLink) . "\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; $cResponseCode = '404'; } } } } // ================================================================== Record Click in NewClix if not a Robot If (($lGo) AND (!$_SESSION['Robot'])){ $cSQL = "INSERT INTO NewClix SET "; $cSQL .= "DateTime='" . $cDateTime . "', "; $cSQL .= "LinkNo='" . $cLinkNo . "', "; $cSQL .= "VisitorIP='" . $cVisitorIP . "', "; $cSQL .= "RemoteHost='" . $cRemoteHost . "', "; $cSQL .= "CalledFrom='" . $cFromPageNo . "', "; $cSQL .= "SiteNo='" . $cSiteNo . "' "; // Add Record to Database $aResult = mysql_query($cSQL, $rdBLink); if (!$aResult){ $cErrMsg .= "Could not insert record into NewClix.\n"; $cErrMsg .= mysql_error() . "\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } else { if (mysql_affected_rows() == 0){ $cErrMsg .= "No record added to NewClix.\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } elseif (mysql_affected_rows() > 1){ $cErrMsg .= "More than one record added to NewClix.\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } } } // ================================================================== Record Click in RobotClix if is a Robot ========= REMOVED 2011-12-31 /* if ($_SESSION['Robot']){ $cSQL = "INSERT INTO RobotClix SET "; $cSQL .= "DateTime='" . $cDateTime . "', "; $cSQL .= "LinkNo='" . $cLinkNo . "', "; $cSQL .= "VisitorIP='" . $cVisitorIP . "', "; $cSQL .= "RemoteHost='" . $cRemoteHost . "', "; $cSQL .= "CalledFrom='" . $cFromPageNo . "', "; $cSQL .= "SiteNo='" . $cSiteNo . "' "; // Add Record to Database $aResult = mysql_query($cSQL, $rdBLink); if (!$aResult){ $cErrMsg .= "Could not insert record into RobotClix.\n"; $cErrMsg .= mysql_error() . "\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } else { if (mysql_affected_rows() == 0){ $cErrMsg .= "No record added to RobotClix.\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } elseif (mysql_affected_rows() > 1){ $cErrMsg .= "More than one record added to RobotClix.\n"; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } } } */ } else { // LinkNo not provided or is invalid EXIT ("Invalid"); } if (!empty($cErrMsg)){ // Compose Error Notice and send to Webmaster $cEmailMsg = "\n"; $cEmailMsg .= " USA WEB DIRECTORIES BANNER AD LINK NOTICE" . "\n"; $cEmailMsg .= "\n"; $cEmailMsg .= " Date: " . $cDate . "\n"; $cEmailMsg .= " Time: " . $cTime . "\n"; $cEmailMsg .= " Visitor IP: " . $cVisitorIP . "\n"; $cEmailMsg .= " Remote Host: " . $cRemoteHost . "\n"; if ($lIsRobot){ $cEmailMsg .= " Robot: Yes\n"; } else { $cEmailMsg .= " Robot: No\n"; } $cEmailMsg .= " Called From: " . $cWebsite . "\n"; $cEmailMsg .= " Page No: " . $cFromPageNo . "\n"; $cEmailMsg .= " LinkNo: " . $cLinkNo . "\n"; $cEmailMsg .= " Link URL: " . $cWebLink . "\n"; $cEmailMsg .= "\n"; $cEmailMsg .= " Response Code: " . $cResponseCode . "\n\n"; // -------------------- Added ResponseCode to message (2011-10-07) $cEmailMsg .= "\n"; $cEmailMsg .= " Error Message: \n"; $cEmailMsg .= "\n"; $cEmailMsg .= "[" . $cErrMsg . "]\n"; $cEmailMsg .= "\n"; $cHeaders = "From: USA Web Advertising \r\n"; if (!empty($cErrMsg)){ mail('LinkError@USAWebAdv.com', $cWebsite . ' BANNER AD Link ERROR Notice', $cEmailMsg, $cHeaders, "-fPublisher@USAWebAdv.com"); } } if ($lGo){ if (substr_count($cWebLink,"http://") > 0){ $cGoTo = $cWebLink; } else { $cGoTo = 'http:/' . '/' . $cWebLink; } // Perform Redirect with Header // header("Status: 200"); header("Location: $cGoTo"); } else { // Reply with Error Status header("Status: " . $cResponseCode); if ($cResponseCode == '503'){ EXIT ("Service Unavailable -- May be a problem with the server. Please try again later."); } elseif ($cResponseCode == '410'){ EXIT ("Gone -- The information requested is no longer a part of our system."); } elseif ($cResponseCode == '404'){ EXIT ("Not Found -- The problem has been reported. Please check your URL or try again later."); } else { EXIT ("Something went wrong. Dunno what it was."); } } %>