<?php
 
require_once('class/UrlShortener.php');
 
 
$short_link = '';
 
 
if (isset($_POST['long_link'])) {
 
    $long_link = '';
 
    
 
    if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc())
 
    {
 
        $long_link = stripslashes($_POST['long_link']);
 
    }
 
    else {
 
        $long_link = $_POST['long_link'];
 
    }
 
    
 
    if (preg_match("#^http(s)?://[a-z0-9-_.]+\.[a-z]{2,4}#i", $long_link)) {
 
        $urlShortener = new UrlShortener();
 
        
 
        $short_link = $urlShortener->getShortUrl($long_link);
 
    }
 
}
 
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<title>Generate Short Link</title>
 
</head>
 
 
<body>
 
<?php if ($short_link != "") { ?>
 
<table width="100%" border="1" cellspacing="0" cellpadding="1">
 
  <tr>
 
    <td>Short link has been generated.</td>
 
  </tr>
 
  <tr>
 
    <td><?php echo $short_link; ?></td>
 
  </tr>
 
  <tr>
 
    <td>Original link: <?php echo $long_link; ?></td>
 
  </tr>
 
</table><br />
 
<?php
 
}
 
?>
 
<form action="" method="post">
 
<table width="100%" border="1" cellspacing="0" cellpadding="1">
 
  <tr>
 
    <td>Long Link</td>
 
    <td><input name="long_link" type="text" /></td>
 
  </tr>
 
  <tr>
 
    <td> </td>
 
    <td><input name="submit" type="submit" value="Generate Short Link" /></td>
 
  </tr>
 
</table>
 
 
 
</form>
 
</body>
 
</html>
 
 |