remove not needed functions
This commit is contained in:
parent
04d41647bc
commit
d2d3c30b4a
22
index.php
22
index.php
|
@ -8,7 +8,7 @@ define("CHARSET", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678
|
|||
$url = "";
|
||||
$link = "";
|
||||
$callback = "NO";
|
||||
|
||||
$dbh = new PDO('mysql:host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS);
|
||||
|
||||
if (DEBUG == 'true') {
|
||||
ini_set('display_errors', 1);
|
||||
|
@ -19,16 +19,6 @@ if (DEBUG == 'true') {
|
|||
ini_set('display_startup_errors', 0);
|
||||
}
|
||||
|
||||
function db_connect() {
|
||||
$dbh = new PDO('mysql:host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS);
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
function count_urls($dbh) {
|
||||
$sth = $dbh->query("SELECT COUNT(*) FROM ". DB_TABLE);
|
||||
return $sth->fetchColumn();
|
||||
}
|
||||
|
||||
function generate_short($url, $dbh) {
|
||||
if(!preg_match("/^((https?|ftp)[:\/\/].*\/{2,})/i",$url)) {
|
||||
return false;
|
||||
|
@ -92,8 +82,7 @@ function find_short($hash, $dbh) {
|
|||
|
||||
if (isset($_POST['url'])) {
|
||||
if ($_POST['url'] != '' && strlen($_POST['url']) > 0) {
|
||||
$db = db_connect();
|
||||
$link = generate_short($_POST['url'], $db);
|
||||
$link = generate_short($_POST['url'], $dbh);
|
||||
} else {
|
||||
$link = false;
|
||||
}
|
||||
|
@ -103,8 +92,7 @@ if (isset($_GET['hash']) && $_GET['hash'] != '' && strlen($_GET['hash']) > 0) {
|
|||
$path = explode('/', $_SERVER['REQUEST_URI']);
|
||||
$uri = $path[count($path)-1];
|
||||
if ($uri != '') {
|
||||
$db = db_connect();
|
||||
$link = find_short($uri, $db);
|
||||
$link = find_short($uri, $dbh);
|
||||
if ($link != '') {
|
||||
header("Cache-Control: no-cache, must-revalidate");
|
||||
header("Expires: Wed, 29 Feb 1984 00:00:00 GMT");
|
||||
|
@ -114,8 +102,8 @@ if (isset($_GET['hash']) && $_GET['hash'] != '' && strlen($_GET['hash']) > 0) {
|
|||
}
|
||||
|
||||
if ($callback == 'NO') {
|
||||
$db = db_connect();
|
||||
$count = count_urls($db);
|
||||
$sth = $dbh->query("SELECT COUNT(*) FROM ". DB_TABLE);
|
||||
$count = $sth->fetchColumn();
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
|
|
Loading…
Reference in New Issue