

URL ShortenerURL Shortener
URL shortener converts long URLs into short, shareable links with redirection.
URL Shortener
URL shortener converts long URLs into short, shareable links with redirection.
Overview
The URL shortener application allows users to input long URLs and generates shorter, more manageable links. It stores the mappings between the original and shortened URLs in a JSON file, enabling persistent access. Users can also opt for custom short codes if desired. When a short URL is accessed, the application redirects the user to the corresponding long URL, making it easier to share links across various platforms. Additionally, it includes CSRF protection to enhance security during form submissions. This tool is useful for simplifying links.
Features
- URL Shortening: Converts long URLs into shorter, shareable links.
- Custom Short Codes: Allows users to create personalized short codes.
- Persistent Storage: Stores URL mappings in a JSON file for long-term access.
- Redirection: Automatically redirects users from short URLs to the original long URLs.
- CSRF Protection: Implements security measures to prevent cross-site request forgery during form submissions.
Requirements
1. PHP Version - PHP 7.0 or higher is recommended for optimal performance and security.
2. Web Server - A web server capable of running PHP, such as Apache or Nginx.
3. File Permissions - The application must have write permissions to the directory where 'urls.json' will be stored, allowing it to create and update the file.
4. JSON Support - PHP must have JSON support enabled (usually enabled by default in modern PHP installations).
5. Session Support - PHP sessions must be enabled to handle CSRF protection and maintain state across requests.
6. Basic HTML/CSS Knowledge - Familiarity with HTML and CSS is helpful for customizing the user interface.
7. Browser - A modern web browser for testing and using the application.
Instructions
To set up the URL shortener application, start by uploading the provided files (`index.php` and `.htaccess`) to your web server. Use an FTP client or your hosting provider's file manager to place these files in the root directory of your web application, typically named `public_html` or `www`.
Once the files are uploaded, ensure that the directory has the appropriate permissions to allow the application to create and write to the `urls.json` file. This file will be automatically generated when a URL is shortened for the first time. If you prefer, you can create an empty `urls.json` file manually in the same directory.
Next, confirm that your server has the `mod_rewrite` module enabled, as the `.htaccess` file relies on it for URL rewriting. This allows users to access shortened URLs without needing to specify the full path. After ensuring everything is in place, navigate to your domain (e.g., `http://yourdomain.com/index.php`) in a web browser to access the application.
Finally, test the functionality by entering a long URL in the input field and clicking the "Shorten" button. If everything is set up correctly, the application will generate a short URL that redirects to the original long URL when accessed. If you encounter any issues, consult your hosting provider's support for assistance.
Category | Scripts & Code / PHP Scripts / Links |
First release | 18 February 2025 |
Last update | 18 February 2025 |
Software version | PHP 7.0, PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 |
Tags | URL Shortener, web hosting, web development, user interface, link management, php application, custom short codes, url redirection, json storage, file permissions, .htaccess configuration, csrf protection, url encoding, seo friendly links, php session management |