I'm currently trying to program a URL shortener, but now I have the problem that I do not know how to program the forwarding.
I've made it so far that you can shorten a URL, e.g. you want to truncate the URL of YouTube, then create an entry in a database that "links" the YouTube URL to a randomly generated ID, say this ID is illustrative 'dzUejsg'
Now I want to be redirected to the linked URL when entering sampleurl.com/dzUejsg
, just I do not know exactly how to do that ...
I hope you can help me. Thanks in advance for all your answers! (Sorry for bad English, I'm german.)
~ JustMarvin
If the ID stored in the database is extracted from the URL (ex. https://youtube.com/watch?q=123 and the ID is 123) then you could use the header("Location: $url")
function.
For example:
$url = "https://youtube.com/watch?v=".$id; // Where id is the id from the database.
header("Location: $url");
TL;DR Use the header("Location: <location>");
function