URL Shortener
URL Shortener
Shortened URL:
{$_SERVER['HTTP_HOST']}/$shortCode";
}
// Function to generate a unique short code (you can implement your logic here)
function generateUniqueShortCode() {
// Generate a unique code (e.g., using random characters)
return substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, 6);
}
// Function to save the mapping of short code to original URL
function saveMapping($shortCode, $originalUrl) {
// You can save this in a database or a file
// Example with a file:
file_put_contents("short_urls.txt", "$shortCode:$originalUrl\n", FILE_APPEND);
}
?>
Comments
Post a Comment