Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions remove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/*
* First authored by Brian Cray
* Page created by Defyworks
* License: http://creativecommons.org/licenses/by/3.0/
* Contact the author at http://briancray.com/
* Contact the page creator at https://www.defyworks.com/
*/

ini_set('display_errors', 0);

$url_to_remove = get_magic_quotes_gpc() ? stripslashes(trim($_REQUEST['shorturl'])) : trim($_REQUEST['shorturl']);

if(!empty($url_to_remove))
{
require('config.php');

// check if the client IP is allowed to shorten
if($_SERVER['REMOTE_ADDR'] != LIMIT_TO_IP)
{
die('You are not allowed to remove shortened URLs with this service.');
}

// check if the URL exists
$id_to_remove = getIDFromShortenedURL($url_to_remove);

$urlcheck = mysql_result(mysql_query('SELECT id FROM ' . DB_TABLE. ' WHERE id="' . mysql_real_escape_string($id_to_remove) . '"'), 0, 0);

if(!empty($urlcheck))
{

$creator = mysql_result(mysql_query('SELECT creator FROM ' . DB_TABLE. ' WHERE id="' . mysql_real_escape_string($id_to_remove) . '"'), 0, 0);
if($creator != $_SERVER['REMOTE_ADDR'])
{
die('You are not the creator of this URL!');
} else {
mysql_query('DELETE FROM ' . DB_TABLE. ' WHERE id="' . mysql_real_escape_string($id_to_remove) . '"');
die('URL Successfully deleted!');
}

}
else
{
// URL doesn't exist
die('URL does not exist on the database!');
}
}

die('ERROR!');

function getIDFromShortenedURL ($string, $base = ALLOWED_CHARS)
{
$length = strlen($base);
$size = strlen($string) - 1;
$string = str_split($string);
$out = strpos($base, array_pop($string));
foreach($string as $i => $char)
{
$out += strpos($base, $char) * pow($length, $size - $i);
}
return $out;
}
20 changes: 20 additions & 0 deletions remover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<title>URL shortener</title>
<meta name="robots" content="noindex, nofollow">
</html>
<body>
<form method="post" action="remove.php" id="remover">
<label for="longurl">Shortlink Alias to remove</label> <input type="text" name="shorturl" id="shorturl"> <input type="submit" value="Remove">
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script>
$(function () {
$('#remover').submit(function () {
$.ajax({data: {shorturl: $('#shorturl').val()}, url: 'remove.php', complete: function (XMLHttpRequest, textStatus) {
$('#shorturl').val(XMLHttpRequest.responseText);
}});
return false;
});
});
</script>
</body>