I have a one-page URL shortening website. When the shortened URL is clicked how can I display a page with an ad on for about 3 seconds?
Code:
<?php
$baseurl = 'http://zumco.co.uk/'; //address to use as the first part of the short URLs (note trailing slash)
$sql_host = 'localhost'; //host of your mysql database (usually localhost)
$sql_user = 'moseleya_moseley'; //mysql user with access to your database
$sql_pass = 'pass'; //password for this user
$sql_db = 'moseleya_turl'; //the name of your database
$db = mysql_connect($sql_host, $sql_user, $sql_pass);
mysql_select_db($sql_db, $db);
if(isset($_GET['k'])) {
$k = mysql_real_escape_string($_GET['k'], $db);
if($result = mysql_query("SELECT `url` FROM `turl` WHERE `key` = '" . $k . "'", $db)) {
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_row($result);
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $row[0]);
exit;
}
}
}
if(isset($_POST['submit'], $_POST['url'])) {
if(filter_var($_POST['url'], FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) !== false) {
$url = mysql_real_escape_string($_POST['url'], $db);
if($result = mysql_query("SELECT `key` FROM `turl` WHERE `url` = '" . $url . "'", $db)) {
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_row($result);
$key = $row[0];
}
}
if(!isset($key) && mysql_query("INSERT INTO `turl` (`url`) VALUES ('" . $url . "')", $db)) {
$id = mysql_insert_id($db);
$key = base_convert($id, 10, 36);
mysql_query("UPDATE `turl` SET `key` = '" . $key . "' WHERE `id` = '" . $id . "'");
}
echo '<a href="' . $baseurl . $key . '" target="_blank">' . $baseurl . $key . '</a>';
}
}
else {
?>
<form method="post" action="index.php">
<label>URL: <input type="text" name="url" id="url" /></label>
<br />
<input type="submit" name="submit" id="submit" value="Shorten" />
</form>
<?php
}
?>
|