Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ovunc Tukenmez  >  URL Shortener  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: sample_script - index.php
Class: URL Shortener
Create and expand short URLs in a MySQL database
Author: By
Last change:
Date: 2012-11-04 15:15
Size: 1,473 bytes
 

Contents

Class file image Download
<?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>&nbsp;</td>
    <td><input name="submit" type="submit" value="Generate Short Link" /></td>
  </tr>
</table>


</form>
</body>
</html>