Advertisement
Guest User

Conf.php

a guest
Jun 27th, 2010
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.78 KB | None | 0 0
  1. <?php /* index.php ( lilURL implementation ) */
  2.  
  3. require_once 'includes/conf.php'; // <- site-specific settings
  4. require_once 'includes/lilurl.php'; // <- lilURL class file
  5.  
  6. $lilurl = new lilURL();
  7. $msg = '';
  8.  
  9. // if the form has been submitted
  10. if ( isset($_POST['longurl']) )
  11. {
  12.     // escape bad characters from the user's url
  13.     $longurl = trim(mysql_escape_string($_POST['longurl']));
  14.  
  15.     // set the protocol to not ok by default
  16.     $protocol_ok = false;
  17.    
  18.     // if there's a list of allowed protocols,
  19.     // check to make sure that the user's url uses one of them
  20.     if ( count($allowed_protocols) )
  21.     {
  22.         foreach ( $allowed_protocols as $ap )
  23.         {
  24.             if ( strtolower(substr($longurl, 0, strlen($ap))) == strtolower($ap) )
  25.             {
  26.                 $protocol_ok = true;
  27.                 break;
  28.             }
  29.         }
  30.     }
  31.     else // if there's no protocol list, screw all that
  32.     {
  33.         $protocol_ok = true;
  34.     }
  35.        
  36.     // add the url to the database
  37.     if ( $protocol_ok && $lilurl->add_url($longurl) )
  38.     {
  39.         if ( REWRITE ) // mod_rewrite style link
  40.         {
  41.             $url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'.$lilurl->get_id($longurl);
  42.         }
  43.         else // regular GET style link
  44.         {
  45.             $url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?id='.$lilurl->get_id($longurl);
  46.         }
  47.  
  48.         $msg = '<p class="success">Seu link &eacute;: <a href="'.$url.'">'.$url.'</a></p>';
  49.     }
  50.     elseif ( !$protocol_ok )
  51.     {
  52.         $msg = '<p class="error">Invalido!</p>';
  53.     }
  54.     else
  55.     {
  56.         $msg = '<p class="error">FAIL!.</p>';
  57.     }
  58. }
  59. else // if the form hasn't been submitted, look for an id to redirect to
  60. {
  61.     if ( isSet($_GET['id']) ) // check GET first
  62.     {
  63.         $id = mysql_escape_string($_GET['id']);
  64.     }
  65.     elseif ( REWRITE ) // check the URI if we're using mod_rewrite
  66.     {
  67.         $explodo = explode('/', $_SERVER['REQUEST_URI']);
  68.         $id = mysql_escape_string($explodo[count($explodo)-1]);
  69.     }
  70.     else // otherwise, just make it empty
  71.     {
  72.         $id = '';
  73.     }
  74.    
  75.     // if the id isn't empty and it's not this file, redirect to it's url
  76.     if ( $id != '' && $id != basename($_SERVER['PHP_SELF']) )
  77.     {
  78.         $location = $lilurl->get_url($id);
  79.        
  80.         if ( $location != -1 )
  81.         {
  82.             header('Location: '.$location);
  83.         }
  84.         else
  85.         {
  86.             $msg = '<p class="error">ERRO 171.</p>';
  87.         }
  88.     }
  89. }
  90.  
  91. // print the form
  92.  
  93. ?>
  94.  
  95. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  96.      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  97.  
  98. <html>
  99.  
  100.     <head>
  101.         <title><?php echo PAGE_TITLE; ?></title>
  102.        
  103.         <style type="text/css">
  104.         body {
  105.             font: .8em "Trebuchet MS", Verdana, Arial, Sans-Serif;
  106.             text-align: center;
  107.             color: #333;
  108.             background-color: #fff;
  109.             margin-top: 5em;
  110.         }
  111.        
  112.         h1 {
  113.             font-size: 2em;
  114.             padding: 0;
  115.             margin: 0;
  116.         }
  117.  
  118.         h4 {
  119.             font-size: 1em;
  120.             font-weight: bold;
  121.         }
  122.        
  123.         form {
  124.             width: 28em;
  125.             background-color: #eee;
  126.             border: 1px solid #ccc;
  127.             margin-left: auto;
  128.             margin-right: auto;
  129.             padding: 1em;
  130.         }
  131.  
  132.         fieldset {
  133.             border: 0;
  134.             margin: 0;
  135.             padding: 0;
  136.         }
  137.        
  138.         a {
  139.             color: #09c;
  140.             text-decoration: none;
  141.             font-weight: bold;
  142.         }
  143.  
  144.         a:visited {
  145.             color: #07a;
  146.         }
  147.  
  148.         a:hover {
  149.             color: #c30;
  150.         }
  151.  
  152.         .error, .success {
  153.             font-size: 1.2em;
  154.             font-weight: bold;
  155.         }
  156.        
  157.         .error {
  158.             color: #ff0000;
  159.         }
  160.        
  161.         .success {
  162.             color: #000;
  163.         }
  164.        
  165.         </style>
  166.  
  167.     </head>
  168.    
  169.     <body onload="document.getElementById('longurl').focus()">
  170.        
  171.         <h1><?php echo PAGE_TITLE; ?></h1>
  172.        
  173.         <?php echo $msg; ?>
  174.        
  175.         <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  176.        
  177.             <fieldset>
  178.                 <label for="longurl">Digite a sua URL:</label>
  179.                 <input type="text" name="longurl" id="longurl" />
  180.                 <input type="submit" name="submit" id="submit" value="Encurtar!" />
  181.             </fieldset>
  182.        
  183.         </form>
  184.  
  185.         <h4>Powered by <a href="http://amaurikx.co.cc">AmauriKnx</a></h4>
  186.    
  187.     </body>
  188.  
  189. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement