Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Here is a tricky one: Whats the quickest way to get the final url from a redirection?

    Hi,

    I want to capture the final url that a website redirects to.

    Here is an example of what I mean:

    www.example.com/sites.php?pd=45

    When you click on that link, the site will redirect you to

    www.Joe-Blogs.com/green/prod1.html?a=527

    As you can see they are two different sites.

    What I would like to do is pick the
    www.Joe-Blogs.com/green/prod1.html part of the final url
    and put it in a variable called $final_url.

    So if I have :

    PHP Code:
    $first_url "www.example.com/sites.php?pd=45"
    What would be the best way to get to that $final_url.

    Should I be using cUrl or would
    file() or get_file_contents() be able to get the url ?

    Any ideas on how I can get to my $final_url ?



    .
    Last edited by jeddi; 02-15-2010 at 10:36 AM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    I just thought that it may look like I am trying
    to build a proxy, but I am not.

    (there are plenty of proxies around already ! )

    I want to use the resulting url in another third party website that does free
    analysis based on the url.

    So if you have any ideas on how I would get a script to follow the
    re-direct an just get the final url... I am all ears




    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    If I use cUrl, the code below should get the to the final webpage right?

    Is the final destination in the HEADER info ?

    PHP Code:
    $target_url "www.example.com/sites.php?pd=45";
    $cef "curl_err.txt"
    $ceh fopen($cef'w');

    curl_setopt($chCURLOPT_USERAGENT$userAgent);
    curl_setopt($chCURLOPT_URL,$target_url);
    curl_setopt($chCURLOPT_FAILONERRORtrue);
    curl_setopt($chCURLOPT_STDERR$ceh);        
    curl_setopt($chCURLOPT_VERBOSE1);
    curl_setopt($chCURLOPT_HEADER,1); 
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_AUTOREFERERtrue);
    curl_setopt($chCURLOPT_BINARYTRANSFER,true);
    curl_setopt($chCURLOPT_TIMEOUT10);

    $output curl_exec($ch);
    $info curl_getinfo($ch); 
    How would I extract the final url ?

    Any ideas ?



    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Doesn't anyone know how to do this ?

    Maybe I should use be using
    fsockopen() to get the final url?

    If any one can help me with this one I would really
    appreciate as I am pretty stuck

    Thanks
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •