Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <head>
- <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
- <meta charset="utf-8" />
- <title>Oleo Acme Redirect</title>
- <link rel="stylesheet" href="style.css">
- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
- <script src='https://www.google.com/recaptcha/api.js'></script>
- </head>
- <body>
- <h1>Oleo Acme Redirect</h1>
- <form>
- <input type="text" name="redirectUrl" placeholder="Redirect Link">
- <input type="submit" name="submit" value="Generate">
- <input type="checkbox" name="hide" value="true">Hide redirect destination<br />
- <div class="g-recaptcha" data-sitekey="6LcLZ2wUAAAAAD5JPq-pu6ciRm7_j6bidwcVPuGA"></div>
- </form>
- <?php
- $conn = mysqli_connect("localhost", "----", "----", 'webDB');
- function IsInDb($key, $value){
- global $conn;
- $sql = "SELECT * FROM `redirects` WHERE binary `".$key."` = binary '".$value."';";
- $result = mysqli_query($conn, $sql);
- if(mysqli_num_rows($result) > 0) return true;
- return false;
- }
- function RandomString($length = 7){
- $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charSize = strlen($char) - 1;
- while (true){
- $str = '';
- for($i = 0; $i != $length; $i++){
- $str = $str.$char[rand(0, $charSize)];
- }
- if(!IsInDb("shortUrl", $str)) break;
- }
- return $str;
- }
- if (isset($_GET['submit']))
- {
- global $conn;
- $url = $_GET['redirectUrl'];
- $hide = (isset($_GET['hide'])? '1' : '0');
- $url = filter_var($url, FILTER_SANITIZE_URL);
- if (filter_var($url, FILTER_VALIDATE_URL)) {
- $secretKey = "-----------------------";
- $responseKey = $_GET['g-recaptcha-response'];
- $capchaUrl = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$responseKey;
- $response = file_get_contents($capchaUrl);
- $response = json_decode($response);
- if ($response->success){
- $short = '';
- if(IsInDb("redirectUrl", $url)){
- $sql = "SELECT `shortUrl` FROM `redirects` WHERE binary `redirectUrl` = binary '".$url."' LIMIT 1;";
- $result = mysqli_query($conn, $sql);
- if(mysqli_num_rows($result) > 0) {
- $short = mysqli_fetch_assoc($result)['shortUrl'];
- }
- }
- else{
- $short = RandomString();
- $sql = "INSERT INTO `redirects` (`redirectUrl`, `shortUrl`, `hide`) VALUES ('".$url."', '".$short."', '".$hide."');";
- $result = mysqli_query($conn, $sql);
- }
- $link = "https://oleo.acme.si/redirect/".$short;
- header("Location: ?short=".$short);
- }
- else{
- echo("<p>reCaptcha verification has failed. Try again.</p>");
- }
- } else {
- echo("<p>".$url." is not a valid URL.</p>");
- }
- }
- else if (isset($_GET['short'])){
- $short = $_GET['short'];
- if(IsInDb("shortUrl", $short)){
- $link = "https://oleo.acme.si/redirect/".$short;
- echo '<p>Generated a redirect url at <a href="'.$link.'">'.$link.'</a></p>';
- }
- else{
- echo "<p>This redirect link doesn't exist</p>";
- }
- }
- else {
- echo "<p>Enter a redirect link</p>";
- }
- ?>
- <br />
- <p>
- Go back <a href="http://oleo.acme.si">home</a>
- </p>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement