Advertisement
guitarman0831

Untitled

Jun 14th, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2.     $longurl = $_GET['longurl'];
  3.     $custom = $_GET['customname'];
  4.    
  5.     if($longurl == "") {
  6.         die(header("Location: http://www.ohjustthatguy.com/htmlshort/?invalidurl=true"));
  7.     }
  8.    
  9.     if(!preg_match("|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i", $longurl)) {
  10.         header("Location: http://www.ohjustthatguy.com/htmlshort/?invalidurl=true");
  11.     }
  12.    
  13.     require_once "/home/a7435766/public_html/scripts/dbconnect.php";
  14.    
  15.     $sqlquery = mysql_query("SELECT * FROM url WHERE shortened = '$custom'");
  16.    
  17.     if(mysql_num_rows($sqlquery) != 0) {
  18.         die(header("Location: http://www.ohjustthatguy.com/htmlshort/?taken=true"));
  19.     }
  20.  
  21.     $urlinput = mysql_real_escape_string($longurl);
  22.     $id=rand(10000,99999);
  23.     if($custom != ""){
  24.         if(strlen($custom) > 4) {
  25.             die(header('Location: http://www.ohjustthatguy.com/htmlshort/?length=true'));
  26.         }
  27.         $shorturl = $custom;
  28.     } else {
  29.         $shorturl=base_convert($id,20,36);
  30.     }
  31.     $sql = "INSERT INTO url VALUES('$id','$urlinput','$shorturl')";
  32.     mysql_query($sql);
  33.     header('Location: http://www.ohjustthatguy.com/htmlshort/disp.html?customurl=' . $shorturl);
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement