No URL supplied';
$l_yoururl = '
الرابط المختصر:';
$l_invalidurl = '
الرابط غير صالح.';
$l_createurl = 'اختصر الرابط';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if($action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl}
{$shorturl}";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if($action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
//////////////////// FEEL FREE TO EDIT BELOW ////////////////////
?>