Skip to content

Instantly share code, notes, and snippets.

@ScruffyRules
Created January 11, 2015 21:19
Show Gist options
  • Save ScruffyRules/afc81e89e51bed741748 to your computer and use it in GitHub Desktop.
Save ScruffyRules/afc81e89e51bed741748 to your computer and use it in GitHub Desktop.
ShareX URL Shortener
RewriteEngine On
RewriteRule ^(?!.*\.php)(.*)$ go.php?jam=$1 [NC,L]
<?php
if(!isset($_GET['jam'])) {
header("HTTP/1.0 400 Bad Request");
die("HTTP/1.0 400 Bad Request");
}
if (!file_exists($_GET['jam'])) {
header("HTTP/1.0 400 Bad Request");
die("HTTP/1.0 400 Bad Request");
}
header("Location: ".file_get_contents($_GET['jam']));
die();
?>
{
"Name": "ScruffyRules.com_Shortener",
"RequestType": "POST",
"RequestURL": "http://scruffyrules.com/s/new.php",
"FileFormName": "",
"Arguments": {
"url": "$input$"
},
"ResponseType": "Text",
"RegexList": [],
"URL": "",
"ThumbnailURL": "",
"DeletionURL": ""
}
<?php
//Number of characters to be shown when a random file name is generated
$url_length = 6;
//URL which will be displayed after upload (URL will have the file name appended)
$url = "http://scruffyrules.com/s/";
if(!isset($_POST['url'])) {
header("HTTP/1.0 400 Bad Request");
die("HTTP/1.0 400 Bad Request");
}
$name = generateRandomString();
file_put_contents($name, $_POST['url']);
echo $url.$name;
function generateRandomString() {
global $url_length;
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $url_length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
?>
@dotziph
Copy link

dotziph commented Jul 15, 2019

I want the links to be in there own directory like example.com/s/uYLsKi I've tried to figure it out but I can't.

@ScruffyRules
Copy link
Author

Also I'd probably not use this since it creates a file per URL which is pretty bad.

@dotziph
Copy link

dotziph commented Jul 15, 2019

Well this is the only one I could find so I was ok with what ever. Have you thought about making a more up to date one that works better?

@ScruffyRules
Copy link
Author

Not really, never really used it.

@dotziph
Copy link

dotziph commented Jul 15, 2019

Guess my search continues thanks for at least making something that works

@karamankaan
Copy link

How do I use the PHP files(new.php, go.php) in ShareX?

@dotziph
Copy link

dotziph commented Jan 15, 2020

you upload those files to your site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment