Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Display ad page on redirect
Old 05-24-2010, 11:39 AM Display ad page on redirect
Extreme Talker

Posts: 193
Name: Adam Moseley
Trades: 0
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
}
?>
aadam is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-24-2010, 01:50 PM Re: Display ad page on redirect
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You use an interstitial page with a javascript timer that calls the redirect URI on timeout.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-26-2010, 07:14 PM Re: Display ad page on redirect
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
Dont even need to get that convoluted

Use a <meta refresh

<meta http-equiv="refresh" content="5;url=newpage.php">
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Display ad page on redirect
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15483 seconds with 12 queries