-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.php
36 lines (32 loc) · 991 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
require('config.php');
// check if the client IP is allowed to shorten
if($_SERVER['REMOTE_ADDR'] != LIMIT_TO_IP) {
// Soft redirect
header('Location: https://yourdomain.com');
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP URL Shortener</title>
<meta name="robots" content="noindex, nofollow">
</head>
<body>
<form method="post" action="shorten.php" id="shortener">
<label for="longurl">URL to shorten</label> <input type="text" name="longurl" id="longurl"> <input type="submit" value="Shorten">
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#shortener').submit(function () {
$.ajax({data: {longurl: $('#longurl').val()}, url: '/shorten/', complete: function (XMLHttpRequest, textStatus) {
$('#longurl').val(XMLHttpRequest.responseText);
}});
return false;
});
});
</script>
</body>
</html>