Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- mysql_connect("localhost", "UN", "PWD") or die("<b>1</b> ".mysql_error());
- mysql_select_db("turt2l5_site") or die("<b>2</b> ".mysql_error());
- define("TABLE", "longurls");
- if(isset($_POST['url'])){
- $url = clean($_POST['url']);
- if(stristr($url, "http://") === FALSE){
- $url = "http://".$url;
- }
- if(!(stristr($url, "long.turt2live") === FALSE)){
- die("Nope, Sorry NuclearW<br><a href='index.php'>Try again</a>");
- }
- $longurl = "http://google.com";
- $query = mysql_query("SELECT * FROM ".TABLE." WHERE ourl='".$url."'") or die("<b>3</b> ".mysql_error());
- if(mysql_num_rows($query)>=1){
- $row = mysql_fetch_array($query);
- $longurl = $row['url'];
- }else{
- $longurl = sha1($url).sha1(md5($url)).md5(sha1($url));
- if(isset($_POST['superlong'])){
- $longurl = sha1($url).sha1(md5($url)).md5(sha1($url)).sha1($url).sha1(md5($url)).md5(sha1($url)).sha1($url).sha1(md5($url)).md5(sha1($url));
- }
- mysql_query("INSERT INTO ".TABLE." (ourl, url) VALUES ('".$url."', '".$longurl."')") or die("<b>4</b> ".mysql_error());
- }
- echo "<h2>$url = <a href='http://long.turt2live.com/?url=$longurl'>http://long.turt2live.com/?url=$longurl</a></h2>";
- echo "Don't know what to do? Copy and paste this: <br><input type='text' style='width:400px' value='http://long.turt2live.com/?url=$longurl'><br><i>Hint: Use CTRL+A on Windows to select all</i>";
- echo "<hr>";
- }else{
- if(isset($_GET['url'])){
- $url = clean($_GET['url']);
- $query = mysql_query("SELECT * FROM ".TABLE." WHERE url='".$url."'") or die("<b>5</b> ".mysql_error());
- if(mysql_num_rows($query)>=1){
- $row = mysql_fetch_array($query);
- if(isset($_GET['preview'])){
- echo "<i>http://long.turt2live.com/?url=$url points to :</i> <b>".$row['ourl']."</b>";
- echo "<hr>";
- }else{
- header("Location: ".$row['ourl']);
- }
- $longurl = $row['url'];
- }else{
- echo "I don't know what you are looking for...";
- }
- }
- }
- echo "<h1>Long URL</h1>";
- echo "<form action='index.php' method='post'>";
- echo "URL: <input type='text' name='url' style='width:300px;'>";
- echo "<input type='checkbox' name='superlong' value='yes'> Super Long URL<br>";
- echo "<input type='submit' name='submit' value='Longify'>";
- echo "<form>";
- echo "<hr>";
- echo "<h3>Unsure of where a link goes? <a href='preview.php'>Click here</a></h3>";
- function clean($input){
- if(get_magic_quotes_gpc()){
- $input = stripslashes($input);
- }
- //$input = mysql_real_escape_string($input);
- $input = htmlentities($input, ENT_COMPAT, "UTF-8");
- return $input;
- }
- ?>
- <hr>Copyright © turt2live 2012
Advertisement
Add Comment
Please, Sign In to add comment