Skip to content

Instantly share code, notes, and snippets.

@OutlawGameTools
Created December 6, 2018 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OutlawGameTools/a1270b06a1d4b321f4345f7dd74528bb to your computer and use it in GitHub Desktop.
Save OutlawGameTools/a1270b06a1d4b321f4345f7dd74528bb to your computer and use it in GitHub Desktop.
<?php
ob_start();
include 'act_dbconnect.php';
//
// Sonic Sneak - Server Edition
// Another Mohawk Man Creation
// Copyright 2006-2009 Jay Jennings
function db_search($search_value)
{
$qry = "select code, linkurl, pagetitle, framed from codes where code = '" . $search_value . "'";
$result = dbhit($qry);
if ($result == 0)
die(mysql_error());
if (mysql_num_rows($result) != 0)
{ // if a row was returned, get info from it
$row = mysql_fetch_array($result);
$linkurl = $row['linkurl'];
$pagetitle = $row['pagetitle'];
$framed = $row['framed'];
return array($linkurl, $pagetitle, $framed);
}
else
return false;
}
function sendEmail($badCode)
{
if ($badcode == "/")
return;
$qry = "select adminemail, ntfylink from config";
$result = dbhit($qry);
if ($result == 0)
die(mysql_error());
if (mysql_num_rows($result) != 0)
{ // if a row was returned, get info from it
$row = mysql_fetch_array($result);
$admin = $row['adminemail'];
if ($row['ntfylink'] == 1)
mail($admin, "Bad Link From Sonic Sneak", "Could not find link: " . $badCode);
}
}
// take care of setting $the_referer var in case there isn't one naturally
if (isset($_SERVER['HTTP_REFERER']))
$the_referer = $_SERVER['HTTP_REFERER'];
else
$the_referer = "(no referer)";
//-------------------------------------------------------------------------------------
// split the query string into pieces.
// check to see whether link is dir/foo/bar or dir?foo/bar
if(!isset($_SERVER['REQUEST_URI']))
{
if(isset($_SERVER['SCRIPT_NAME']))
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
else
$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING'])
{
$_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
}
}
$pos = strpos($_SERVER['REQUEST_URI'], "?");
if ($pos === false)
{
$qpieces = explode("/", $_SERVER['REQUEST_URI']);
$fudge = 2;
}
else
{
$qpieces = explode("/", $_SERVER['QUERY_STRING']);
$fudge = 0;
}
$linkcode = $qpieces[$fudge+0];
// strip off any .suffix from the code
$linkcode_array = explode(".", $linkcode);
$linkcode = $linkcode_array[0];
// get the sublink ready if available
if (count($qpieces) > ($fudge + 1))
$sublink = trim($qpieces[$fudge+1]);
else
$sublink = "";
$result = db_search($linkcode);
$url = $result[0];
$pagetitle = $result[1];
$framed = $result[2];
//echo $url;
//exit;
if ($url == false)
{
echo "That link could not be found. The admin has been notified.";
if (trim($linkcode) != "")
{
sendEmail($linkcode . "/" . $sublink);
//header("Location: http://jayjennings.com");
}
exit();
}
// replace {tracking} in redirect with the sublink (tracking token)
$url = str_replace ("{tracking}", $sublink, $url);
//=======================================================
// check to see if we need to do a zero frame thing
// or whether we should just do a straight redirect
//-------------------------------------------------------
if ($framed > 0)
{
// create some code if we need a zeroframe page
$pageInfo = "<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><title>" . $pagetitle . "</title></head>";
$pageInfo .= "<frameset frameborder=\"no\" rows=\"0,*\"><frame src=\"\" name=\"frame1\"><frame src=\"" . $url . "\" name=\"frame2\"></frameset></html>";
echo $pageInfo;
}
else
{
//===========================================
// send the user to wherever they want to go.
header("Location: " . trim($url));
}
//===========================================
// save the info in the counter file
if ($sublink != "test")
{
//echo "[" . trim($sublink) . "]\n";
// strip off any .suffix
$tracktoken = explode(".", $sublink);
$sublink = $tracktoken[0];
$trackstring = $linkcode . "," . $sublink . "," . $_SERVER['REMOTE_ADDR'] . "," . date("Y-m-d") . " " . date("H:i:s") . "," . $the_referer . "\r\n";
$qry = "insert into trackdata (code, campaign, ip, referer, siteid) values ('" . $linkcode . "', '" . $sublink . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $the_referer . "', 1)";
$result = dbhit($qry);
if ($result == 0)
die(mysql_error());
}
ob_end_flush();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment