1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Getting the url *after* a redirect

Discussion in 'PHP' started by Dejavu, Aug 27, 2005.

  1. #1
    Dejavu, Aug 27, 2005 IP
    SEMrush
  2. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you clarify a bit? Do you mean that you want to parse a link like the above, in order to extract the URL that is being redirected to? If so, using a regular expression (PHP's ereg & preg functions) would be the best way to do what you want; I can give you an example if you want...
     
    Willy, Aug 27, 2005 IP
  3. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no, that was just an example
    what I mean is how do I know the final url of a link. If a link redirects to another, I want the last thing that ends up in my url bar.
    eg http://tinyurl.com/1c2 redirects to google.com, but how do I get that?
     
    Dejavu, Aug 27, 2005 IP
  4. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh, I see. Well, there is no way to know that without actually following those links. Essentially what you have to do is find or write a small HTTP client, a "mini web robot", that will request the initial URL, check the response for a redirect, request the URL that was redirected to, check the response for another redirect, and so on... You get the idea ;)

    You should be able to do this fairly easily with PHP's CURL library.
     
    Willy, Aug 27, 2005 IP