Url Shortner Script Need Help

Discussion in 'PHP' started by masterklik, Jun 21, 2009.

  1. #1
    When i use this index.php on my hosting.
    this index.php for url shortner doesnt want to redirect the short url to main domain.
    Where is the problem?
    thx

     
    masterklik, Jun 21, 2009 IP
  2. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #2
    The most important thing is that your host sends unknown pages back to the home page.

    Here is My working code. I wrote functions to to the lookups, but I dont want to post them, as they are common mysql statements.
    
    $curpage = curPageURL();
    
    $isshort = dbcount("SELECT * FROM urls where shorturl='$curpage'")
    
    if ($isshort)
      {
      $su = $curpage; 
      $result = selectdb("SELECT * FROM urls WHERE shorturl ='$su'");
         while($row = mysql_fetch_array($result)) {
        $long = $row["longurl"];
        }
      echo '<html><head>'; 
      echo '<meta http-equiv="refresh" content="0;url='.$long.'">';
      echo '</head><body></body></html>';
      exit;
      }
    
    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     $pageURL = str_replace('DOMAIN','',$pageURL); //Remove the http://domain.com
     return $pageURL;
    }
    
    PHP:
     
    dweebsonduty, Jun 27, 2009 IP