|Create URL Shortener PHP Script Without Database|
Exthemes Dev Blog – Create URL shortener PHP Without Database, demo & download simple PHP URL shortener script and tutorial with PHP sample code.
How to Create a URL Shortener
We need a simple HTML Form, and a shortener.php file to process the request, and we need a redirect.php file to redirect the user to a long link, the idea needs to be database, but we will use another way, instead of database, we will using .TXT files. After all we need a .htaccess file to hide the redirect.php file, and we need a robots.txt file to hide our TXT database from search engines, our PHP script is safe and simple and works well.
Table Of Contents
How to Usage
Download PHP Script, unzip file, open “shortener.php” file, change website link “https://url.ex-themes.com” to your website link, upload script files to your hosting, enjoy.
In “index.php” file we have simple HTML Form and PHP Session:
<?php // By exthemes dev blog | ex-themes.com session_start(); $_SESSION['prevent_repeat'] = rand(); // Prevent a repeat of the process ?> <form method="post" action="shortener.php"> <p>Enter a long link: <input type="text" name="my-link" value=""></p> <p><input type="submit" value="Shorten!"></p> </form>