PDA

View Full Version : Inserting an interstitial page into this php code


AuxiTrooper
01-13-2008, 09:00 PM
I have a small page that generates a shorter url from a url a person would enter. As it is now, when a person clicks http://url.lotpatrol.com?x=1 they go directly to the link associated with the id. Would it be possible to have them go to a "thanks for using this page" and then be forwarded to the page associated with the id?

I don't want to destroy the database or lose anything that people have used already. How can I do this? I don't know where to begin.

<center>
<?
##### SETTINGS ###############################
DB settings would be here
##### SETTINGS ###############################
$sqlconnt = mysql_connect($hostname,$username,$password) or die("<pre><h2><b>ERROR</b> - Could not connect to the database.</h2></pre>");$selectdb = mysql_select_db("$database",$sqlconnt) or die("<pre><h2><b>ERROR</b> - Could not select the database.</h2></pre>");$x=floor($_GET['x']);if($x){ $res = mysql_query("SELECT url FROM shorturl WHERE id=$x"); $row = mysql_fetch_array($res); if($row) echo header("Location:$row[0]"); else echo header("Location:$rootlink");}else{ $u = $_POST['u']; if(($u)&&($u!="http://")) { mysql_query("INSERT INTO shorturl (url) VALUES ('$u')"); $x = mysql_insert_id(); } echo "<html><head><title>$sitetitl</title><link rel='stylesheet' type='text/css' href='images/styles.css'></head>"; echo "<body><center>"; echo "<div id='logo'><a href='$rootlink'><img src='images/logo.gif' width='$lgwidthh' height='$lgheight' border='0'></a><br>Use this free service to turn long links/url's into short, easy to remember, links!<br><b>Turn this</b>: http://www.yourhost/yourhostname/foldera/folderb/yourusername/yourfile<br><b>Into This</b>: http://url.lotpatrol.com/?x=7<br>This can be a big help when you need to send a long link in an email where it might become broken or distorted.</div>"; echo "<form method='post' action='.'>"; echo "<input type='text' name='u' size='60' value='http://'>"; echo "<input type='submit' value='Generate Short URL'>"; echo "</form>"; if(($u)&&($u!="http://")) echo "<h3>Your Short URL: <a href='$rootlink/?x=$x' target=_blank>$rootlink/?x=$x</a></h3>"; else { echo "<table><tr>"; echo "<td id='info'><li>Redirection to any page.</li><li>It's easy to remember.</li></td>"; echo "<td id='info'><li>Easily make any url short.</li><li>Friendly link for SMS.</li></td>"; echo "</tr></table>"; } ; echo "</center></body></html>";}
?>

</center>

KaLibuR
01-13-2008, 10:32 PM
Hey Auxi,

Sure it's possible. Instead of heading the location directly to the link, direct it to a page like "thanks.php" and send the location through to that page in any way you wish (for this example I'll use a query string) and then allow JavaScript to direct after x amount of seconds. From reading your code, I'm assuming $row[0] contains the URL that the page is heading to, so;

Page: thanks.php?x=$row[0]

<HTML>
<HEAD>
<TITLE>Thanks for using our page - Redirecting you soon!</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function redireccionar() {
setTimeout("location.href='<?php echo $_GET['x']; ?>'", 5000);
}
</SCRIPT>
</HEAD>
<BODY onLoad="redireccionar()">
Thanks for using our page. You will be forwarded automatically in 5 seconds.
</BODY>
</HTML>


Now instead of heading to the url directly, head toward the thankyou page. I havn't tested the code above so give it a try and tell me how it worked out! :)

Hope this helps (feel free to PM me),
KaLibuR

AuxiTrooper
01-14-2008, 11:17 AM
that was exactly what i needed! works great! thank you very much!