Source code file content
subversion / 2c.lt / write.php
Size: 4702 bytes, 1 line
<?php
session_start();
require('functions.php');
define("URLNO", " Neįvedėte URL!", true);
if (empty($_POST['url']) or ($_POST['url']=="Įveskite ilgą URL")){
$_SESSION['NoUrl']=URLNO;
header("Location: index.php");
}
else{
require ("a/conf.php");
$ip = $_SESSION['ip'];
$PriesMin=time()-10;
$LaikoPatikrosUzklausa="SELECT ip, timestamp from urls where ip='".$ip."' order by timestamp desc limit 1";
$Rez=mysql_query($LaikoPatikrosUzklausa);
$row=mysql_fetch_array($Rez);
if ($row['timestamp']>$PriesMin){
$_SESSION['ToFast']="Nepraėjo 10 sekundžių!";
header("Location: index.php");}
else{
// Tikrinam, ar tikras url
$url = strip_tags(trim($_POST['url']));
if(url_validate($url))
{
////Tikrinam, ar trumpas url dar nesugeneruotas
// print_r($url);
if (mb_substr($url, 0,12)=="http://2c.lt")
{
$galune=mb_substr($url, 13);
};
if (isset($galune)){
$query = "select suffix, timestamp, url from urls where suffix='".$galune."' order by timestamp desc limit 1";
}else
{ $query = "select suffix, timestamp, url from urls where url='".$url."' order by timestamp desc limit 1";}
// print_r($suffix);
require ("a/conf.php");
$ats=mysql_query($query);
$row=mysql_fetch_array($ats);
mysql_close();
if(isset ($row['suffix'])){
$_SESSION['ShortUrl']="http://2c.lt/".$row['suffix'];
header("Location: index.php");}else{
//Generuojam URL galūnę
BornShortUrl ();
//Pasiziurim tinklapio title
if (file_get_contents($url)){
$content = file_get_contents($url);
$title = htmlentities(getMetaTitle($content), ENT_QUOTES, 'UTF-8');}
if (empty($title)){
$text=$url;
// Change to the number of characters you want to display
$chars = 40;
$text = $text." ";
$text = substr($text,0,$chars);
//$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
$title=$text;
/* $search = array('/', '_','-','%','=');
$replace = array('/ ', '_ ','- ','% ','= ');
$title = str_replace($search, $replace, $title);*/
}
//Įrašom URL į DB
require ("a/conf.php");
$ip = $_SESSION['ip'];
$timestamp=time();
$irasas =( "INSERT INTO urls (suffix, url, ip, timestamp, title)VALUES ('$suffix','$url','$ip','$timestamp', '$title')");
mysql_query($irasas) or die(mysql_error());
mysql_close();
if ($irasas){
$_SESSION['ShortUrl']="http://2c.lt/".$suffix;
header("Location: index.php");}
else {
$_SESSION['WrongUrl'] = 'Invalid query: ' . mysql_error() . "\n";
header("Location: index.php");};
}}
else {
$_SESSION['WrongUrl']="Netaisyklingas ilgas URL! <br /> Galbūt naudojote neleistinus simbolius arba neparašėte http:// (https:// , ftp:// )";
header("Location: index.php");
}}
};
?>





