<% // SendTo.htm ======================================================= FOR LISTINGS // Usage: http://www.usawebadv.com/SendTo.htm?IDNo=00000&From=00000 // Usage: http://www.usawebadv.com/SendTo.htm?IDNo=<$cListNo>&From=<$cPageNo> // This is the main script that receives a 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']))){ $cListNo = $_GET['IDNo']; } else { $cListNo = '000000'; $cErrMsg = "No List-ID No. included in URL.\n"; } // ======================================================= GET From if ((isset($_GET['From'])) AND (!empty($_GET['From']))){ $cFromPageNo = $_GET['From']; } 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 = ""; $cBusName = ""; $cWebsite = ""; $lGo = FALSE; $cResponseCode = '200'; $cSQL = ""; if (($cListNo <> "000000") AND ($cListNo < '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, SiteNo and Website Name $cSQL = "SELECT "; $cSQL .= "Listings.WebLinkURL, "; $cSQL .= "Listings.Website, "; $cSQL .= "SiteList.SiteNo "; $cSQL .= "FROM Listings "; $cSQL .= "LEFT JOIN SiteList ON Listings.Website=SiteList.Website "; $cSQL .= "WHERE Listings.ListNo='" . $cListNo . "' "; $cSQL .= "AND SiteList.Main='T' "; // Run the SQL Query $aResult = mysql_query($cSQL, $rdBLink); if (!$aResult){ $cErrMsg .= "Could not run the Listings 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['WebLinkURL']; $cWebsite = $aRow['Website']; $cSiteNo = $aRow['SiteNo']; $lGo = TRUE; } elseif (mysql_num_rows($aResult) == 0){ $cErrMsg .= "No record of Listing No. " . $cListNo . ".\n"; $cResponseCode = '410'; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } elseif (mysql_num_rows($aResult) > 1){ $cErrMsg .= "More than one record for Listing No. " . $cListNo . ".\n"; $cResponseCode = '404'; $cErrMsg .= "cSQL:[" . $cSQL . "]\n"; } } } } // ================================================================== Record Click in NewClix if not a Robot If (($lGo) AND (!$_SESSION['Robot'])){ $cSQL = "INSERT INTO NewClix SET "; $cSQL .= "DateTime='" . $cDateTime . "', "; $cSQL .= "ListNo='" . $cListNo . "', "; $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']){ // Add Record to RobotClix $cSQL = "INSERT INTO RobotClix SET "; $cSQL .= "DateTime='" . $cDateTime . "', "; $cSQL .= "ListNo='" . $cListNo . "', "; $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"; } 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 { // ListNo not provided or is invalid EXIT ("Invalid"); } if (!empty($cErrMsg)){ // Compose Error Notice and send to Webmaster $cEmailMsg = "\n"; $cEmailMsg .= " USA WEB DIRECTORIES LISTING LINK NOTICE" . "\n"; $cEmailMsg .= "\n"; $cEmailMsg .= " LinkNo: " . $cLinkNo . "\n"; $cEmailMsg .= " Date: " . $cDate . "\n"; $cEmailMsg .= " Time: " . $cTime . "\n"; $cEmailMsg .= " Visitor IP: " . $cVisitorIP . "\n"; $cEmailMsg .= " Remote Host: " . $cRemoteHost . "\n"; $cEmailMsg .= " Called From: " . $cWebsite . "\n"; if ($lIsRobot){ $cEmailMsg .= " Robot: Yes\n"; } else { $cEmailMsg .= " Robot: No\n"; } $cEmailMsg .= " Page No: " . $cFromPageNo . "\n"; $cEmailMsg .= " Link URL: " . $cWebLink . "\n"; $cEmailMsg .= "\n"; $cEmailMsg .= " Response Code: " . $cResponseCode . "\n\n"; // -------------------- Added ResponseCode to message (2011-10-07) $cEmailMsg .= "\n"; if (!empty($cErrMsg)){ $cEmailMsg .= " Error Message:\n"; $cEmailMsg .= "\n"; $cEmailMsg .= $cErrMsg . "\n"; $cEmailMsg .= "\n"; } $cHeaders = "From: USA Web Advertising \r\n"; mail('LinkError@USAWebAdv.com', $cWebsite . ' LISTING 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."); } } %>