commit - 04d41647bc0641805951eb3aa2d72bd2cdfb97ea
commit + d2d3c30b4aecc2fdee9aaa61e48abaeaec2a1fe1
blob - 9e851c0b41c081cb2b798219a4ad9fec8d20f52b
blob + 7afafe038217e23562557f8eda777d1c76df2f7a
--- index.php
+++ index.php
$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);
ini_set('display_startup_errors', 1);
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;
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;
}
$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");
}
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>