I have seen this code from https://www.codexworld.com to Create a URL Shortener using PHP.
// Include database configuration file
require_once 'dbConfig.php';
// Include URL Shortener library file
require_once 'Shortener.class.php';
// Initialize Shortener class and pass PDO object
$shortener = new Shortener($db);
// Long URL
$longURL = 'https://www.codexworld.com/tutorials/php/';
// Prefix of the short URL
$shortURL_Prefix = 'https://localhost/'; // with URL rewrite
$shortURL_Prefix = 'https://localhost/?c='; // without URL rewrite
try{
// Get short code of the URL
$shortCode = $shortener->urlToShortCode($longURL);
// Create short URL
$shortURL = $shortURL_Prefix.$shortCode;
// Display short URL
echo 'Short URL: '.$shortURL;
}catch(Exception $e){
// Display error
echo $e->getMessage();
}
I have understood how the system goes but dont know how can this line of code $longURL = 'https://www.codexworld.com/tutorials/php/';
will not be based on static value but will be dynamic by collecting the link where the user will type it using a textbox input in a form?
How can I do that? Thank you in advance!