<?php
define("SQL_HOST","MySQL-Server");
define("SQL_USER","MySQL-Nutzer");
define("SQL_DATABASE","MySQL-Datenbank");
define("SQL_PASS","MySQL-Passwort");
function sql($abfrage)
{
return mysqli_query(mysqli_connect(SQL_HOST,SQL_USER,SQL_PASS,SQL_DATABASE),$abfrage);
}
function sql_assoc($abfrage)
{
return mysqli_fetch_assoc(sql($abfrage));
}
function sql_num($abfrage)
{
return mysqli_num_rows(sql($abfrage));
}
function sql_assign($abfrage,$wert)
{
$abfrage = sql_assoc($abfrage);
return $abfrage[$wert];
}
function zahl($var)
{
return preg_match("=^[0-9]+$=i",$var);
}
function sec_url($kb,$gb,$sz,$z,$u=0)
{
if (!zahl($kb) or !zahl($gb) or !zahl($sz) or !zahl($z) or !zahl($u))
{
return false;
}
else
{
$url = array();
$var["kb"] = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x","y","z");
$var["gb"] = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z");
$var["sz"] = array("_","-");
$var["z"] = array("1","2","3","4","5","6","7","8","9","0");
for ($a=0;$a<$kb;$a++)
{
$url[] = $var["kb"][rand(0,count($var["kb"])-(($u==1) ? 1 : 4))];
}
for ($a=0;$a<$gb;$a++)
{
$url[] = $var["gb"][rand(0,count($var["gb"])-(($u==1) ? 1 : 4))];
}
for ($a=0;$a<$sz;$a++)
{
$url[] = $var["sz"][rand(0,count($var["sz"])-(($u==1) ? 1 : 2))];
}
for ($a=0;$a<$z;$a++)
{
$url[] = $var["z"][rand(0,count($var["z"])-1)];
}
$var = array();
shuffle($url);
for ($a=0;$a<count($url);$a++)
{
$url_ret .= $url[$a];
}
$url = array();
return $url_ret;
}
}
if (isset($_GET["link"]))
{
//3-fache Prüfung ob Kurzlink eventuell existiert, verschiedene Variablen
$_GET["link"] = str_replace("-Ampersand-","&",$_GET["link"]);
$sec_url = sec_url(3,3,1,1,1);
if (sql_num("SELECT * FROM `url` WHERE `url` = '".$sec_url."'") > 0)
{
$sec_url = sec_url(3,2,1,2,1);
if (sql_num("SELECT * FROM `url` WHERE `url` = '".$sec_url."'") > 0)
{
$sec_url = sec_url(2,2,1,3,1);
}
}
//Prüfung ob der selbe Link schon existiert um doppelte Einträge zu vermeiden wird der alte Kurzlink ausgelesen
$da = sql_assign("SELECT `url` FROM `url` WHERE MD5(`link`) = '".md5($_GET["link"])."'","url");
if ($da == "")
{
sql("INSERT INTO `url` (`link`,`url`) VALUES ('".mysql_real_escape_string($_GET["link"])."','".$sec_url."')");
$da = sql_assign("SELECT `url` FROM `url` WHERE MD5(`link`) = '".md5($_GET["link"])."'","url");
}
echo $da;
}
else
{
echo "Anweisung nicht verstanden.";
}
?>
| |