0

guys.

I am trying to work on a solution for shortening urls with php. Currently a hash is a bit too long for a commercial link, and APIs for shortening urls are paid, which is not an option for me. Is there a way to shorten a md5 output or any API that works somewhat like bit.ly?

Thanks a lot.

  • `Is there a way to shorten a md5 output or any API that works somewhat like bit.ly?` Yes there is. `md5()`, `\PDO` and `header()` should be all you need. – hppycoder Apr 06 '21 at 14:33
  • If you are going to store your "hashes" with the full URLs in a database, then you can just generate a random string and check if it's already been used. Something like https://stackoverflow.com/questions/4356289/php-random-string-generator – ajCary Apr 07 '21 at 07:37
  • Please provide some of your attempts you've already tried. Or at least what you have found so far. – Hille Apr 07 '21 at 14:52

1 Answers1

0

Require the Package

composer require Kozhinhikkodan/url-short 

Use the namespace and returns 'shortened URL’

# use the package 
use Kozhinhikkodan\UrlShort\UrlShort; 
 
# returns 'shortened URL' 
$UrlShort = new UrlShort(); 
return $UrlShort->short_url($url);