Redirect given a certain url

64 Views Asked by At

I'm writing a url shortener, I already solve url shortening. Given a certain long URL (LURL), I get a CODE with the help of a script and a database to form a short URL (SURL) of the type:

mysite.com/CODE

So the ralationship between the code and the LURL is stored and must be consulted in the DB. Now as you can see I need a way to do that. My plan is that all the all url in mysite.com direct to the same page where the CODE is taken as a parameter and in this way make a consult in the db fetching the code from the SURL and then redirect with a script to the LURL.

I dont want to generate a SURL that uses a GET request like:

mysite.com/?CODE

It would be easier but I decided not to do it because it defeats the propose of url shorteners by occupying a character unnecessarily.

How would you implement it? Is this method convenient? If you do not think so I would really appreciate you give me your opinion. Maybe there are better ways to do it now that I already have the DB and the shortening algorithm. See you later.

1

There are 1 best solutions below

0
On BEST ANSWER

http://www.webcheatsheet.com/PHP/get_current_page_url.php check out the curPageURL() function.

$pageURL = curPageURL();
$itemArray= explode("/", $pageURL);
$myCode = $itemArray[1];

something like that will do, but not tested. It just gives you an idea of what you can do.

also, to get the url, here is an simplified version: http://phpeasystep.com/phptu/27.html