initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
tempStorage/
|
||||||
|
conn.php
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
5E9022E82668985A0143C2969A359F58FEFE2F4E70C30BF1FA753016FDB6FB61 comodoca.com 5c2cdb2ce8a20
|
||||||
18
404.php
Normal file
18
404.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
require "conn.php";
|
||||||
|
|
||||||
|
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
||||||
|
$url = basename($url);
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("SELECT * FROM directories WHERE fromsite = :site");
|
||||||
|
$stmt->bindParam(":site", $url);
|
||||||
|
$stmt->execute();
|
||||||
|
$return = $stmt->fetch(PDO::FETCH_OBJ);
|
||||||
|
$return = $return->tosite;
|
||||||
|
|
||||||
|
if(substr($return, 0, 5)!="http:" && substr($return, 0, 6)!="https:"){
|
||||||
|
$return = "http://".$return;
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: $return");
|
||||||
|
?>
|
||||||
20
done.php
Normal file
20
done.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset=UTF-8>
|
||||||
|
<title>URL Shortener - lukeo.link</title>
|
||||||
|
<meta name=viewport content=width=device-width,initial-scale=1>
|
||||||
|
<link rel=stylesheet href=style.css type=text/css>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id=top class=center>
|
||||||
|
<p>Check out <a href=https://lukeogburn.com/>my main site</a>!</p>
|
||||||
|
</div>
|
||||||
|
<div id=main>
|
||||||
|
<h2 class=center>HERE'S YOUR SHORT URL</h2>
|
||||||
|
<p class=center>lukeo.link/<?=$_GET["code"]?></p>
|
||||||
|
<br>
|
||||||
|
<p class=center><a href=/>Want to make another?</a></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
63
function.php
Normal file
63
function.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
require "conn.php";
|
||||||
|
|
||||||
|
function verifyID($pid){
|
||||||
|
require "conn.php";
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM directories WHERE fromsite = :pid");
|
||||||
|
$stmt->bindParam(":pid", $pid);
|
||||||
|
$stmt->execute();
|
||||||
|
$return = $stmt->fetch(PDO::FETCH_OBJ)->fromsite;
|
||||||
|
return ($return!=NULL)?false:true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function randID($length = 6) {
|
||||||
|
do{
|
||||||
|
if(function_exists("random_bytes")){
|
||||||
|
$bytes = random_bytes(ceil($length/2));
|
||||||
|
}elseif(function_exists("openssl_random_pseudo_bytes")){
|
||||||
|
$bytes = openssl_random_pseudo_bytes(ceil($length/2));
|
||||||
|
}else{
|
||||||
|
throw new Exception("No cryptographically secure random function available.");
|
||||||
|
}
|
||||||
|
$x = substr(bin2hex($bytes), 0, $length);
|
||||||
|
$id = gmp_strval(gmp_init($x, 36), 62);
|
||||||
|
} while(!verifyID($id));
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hyperSearch($text){
|
||||||
|
preg_match_all("#((((-|_){0,}\w)+\.([a-zA-Z]+){2,})|((((http)|(https)):\/\/){1}((-|_){0,}\w)+\.([a-zA-Z]+){2,}))((\w+|-|_|\/|\.)+){0,}#", $text, $match);
|
||||||
|
if($match[0]==NULL){
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hyperSearch($_POST["url"]) == false){
|
||||||
|
header("Location: /?error=hps");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("SELECT * FROM directories WHERE tosite = :site");
|
||||||
|
$stmt->bindParam(":site", $_POST["url"]);
|
||||||
|
$stmt->execute();
|
||||||
|
$return = $stmt->fetch(PDO::FETCH_OBJ)->fromsite;
|
||||||
|
$siteExists = ($return==NULL)?false:$return;
|
||||||
|
|
||||||
|
if($siteExists == false){
|
||||||
|
$fromurl = randID();
|
||||||
|
$tourl = $_POST["url"];
|
||||||
|
$stmt = $conn->prepare("INSERT INTO directories (fromsite, tosite) VALUES (:f, :t)");
|
||||||
|
$stmt->bindParam(":f", $fromurl);
|
||||||
|
$stmt->bindParam(":t", $tourl);
|
||||||
|
$stmt->execute();
|
||||||
|
if(!$stmt){
|
||||||
|
header("Location: /?error=stmt");
|
||||||
|
}else{
|
||||||
|
header("Location: /done.php?code=$fromurl");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
header("Location: /done.php?code=$siteExists");
|
||||||
|
}
|
||||||
|
?>
|
||||||
38
index.php
Normal file
38
index.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset=UTF-8>
|
||||||
|
<title>URL Shortener - lukeo.link</title>
|
||||||
|
<meta name=viewport content=width=device-width,initial-scale=1>
|
||||||
|
<link rel=stylesheet href=style.css type=text/css>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id=top class=center>
|
||||||
|
<p>Looking for <a href=https://lukeogburn.com/>lukeogburn.com</a>?</p>
|
||||||
|
</div>
|
||||||
|
<div id=main>
|
||||||
|
<h2 class=center>URL SHORTENER</h2>
|
||||||
|
<form method=POST action=function.php>
|
||||||
|
<input type=text name=url></input>
|
||||||
|
<button type=submit>SHORTEN</button>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
if(isset($_GET["error"])){
|
||||||
|
switch($_GET["error"]){
|
||||||
|
case "stmt":
|
||||||
|
echo "<p class='center error'>Error creating short URL</p>";
|
||||||
|
break;
|
||||||
|
case "hps":
|
||||||
|
echo "<p class='center error'>Please enter a valid URL</p>";
|
||||||
|
break;
|
||||||
|
case "unr":
|
||||||
|
echo "<p class='center error'>That URL wasn't recognized</p>";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<input type=checkbox id=boo>
|
||||||
|
<div id=cookie><p><label for=boo>This site does <b>not</b> use cookies. You're welcome.</label></p></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
96
style.css
Normal file
96
style.css
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
body{
|
||||||
|
font-family: sans-serif;
|
||||||
|
width: 60%;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
a{
|
||||||
|
text-decoration: none;
|
||||||
|
color: #35c97b;
|
||||||
|
}
|
||||||
|
a:hover{
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Cookie notif*/
|
||||||
|
#boo{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#boo:checked+div{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#cookie{
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
width: 60%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: #252525;
|
||||||
|
}
|
||||||
|
label:hover{
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#top{
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
#top>p{
|
||||||
|
margin: 1em 0 0.7em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main{
|
||||||
|
margin-top: 5vh;
|
||||||
|
}
|
||||||
|
#main>h2{
|
||||||
|
font-weight: 400;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
}
|
||||||
|
.error{
|
||||||
|
color: #ff3939;
|
||||||
|
}
|
||||||
|
|
||||||
|
form{
|
||||||
|
width: 75%;
|
||||||
|
margin: 0 auto;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 5fr 1fr;
|
||||||
|
}
|
||||||
|
form>input, form>button{
|
||||||
|
border: 1px solid #aaa;
|
||||||
|
padding: 0.5em 0.8em;
|
||||||
|
}
|
||||||
|
input{
|
||||||
|
width: calc(100% - 1.6em);
|
||||||
|
border-radius: 0.2em 0 0 0.2em;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
button{
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 0 0.2em 0.2em 0;
|
||||||
|
background-color: #eee;
|
||||||
|
font-size: 0.85em;
|
||||||
|
}
|
||||||
|
button:hover{
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1000px){
|
||||||
|
body, #cookie{
|
||||||
|
width: 70%;
|
||||||
|
}
|
||||||
|
form{
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (max-width: 600px){
|
||||||
|
body, #cookie{
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user