url after redirected

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
diamondnular
Forum Newbie
Posts: 3
Joined: Sat Mar 03, 2007 9:43 am

url after redirected

Post by diamondnular »

Hi all,

Is there any way to grab the final url after you go to an url and are redirected? For example, you have the source url http://www.source and if you go to that url, you will be redirected to http://www.destination. I want to grab that destination url but do not know how. Please help.

Thanks,

KC.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Grab it in.. PHP? Well, that all depends on how the redirection is done. If it's done with headers, cURL, fsockopen(), even get_headers() among others can give you the headers. If it's done via <meta> or Javascript, you'll have to parse the response yourself.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Which are you trying to get the destination from? The destination or the source?
diamondnular
Forum Newbie
Posts: 3
Joined: Sat Mar 03, 2007 9:43 am

Post by diamondnular »

feyd wrote:Grab it in.. PHP? Well, that all depends on how the redirection is done. If it's done with headers, cURL, fsockopen(), even get_headers() among others can give you the headers. If it's done via <meta> or Javascript, you'll have to parse the response yourself.
Hi feyd, is there a way to know that the redirection is done by something? I even do not know how it is redirected :(
superdezign wrote:Which are you trying to get the destination from? The destination or the source?


Hi superdezign, I want to create a php script, in that I can paste the source url, and after running it, it will give out the destination url.

Thanks,

KC.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you don't know where the redirection may be, you will have to parse the data yourself. I've already linked to the functions needed.
diamondnular
Forum Newbie
Posts: 3
Joined: Sat Mar 03, 2007 9:43 am

Post by diamondnular »

Hi feyd,

If the url keeps unchanged after redirected, does that mean redirect is done by server or htaccess? If that is the case, can we make a php script to catch the final url? I try to use curl, but the final url is... still the source one :cry:

Thanks,

KC.
Post Reply