Jump to content

cURL server-side redirection not working 100% of time - urgent help needed


PHPNerd3

Recommended Posts

Hi All,

 

My goal is to process all redirects serverside and simply return the user to the 'final' URL.

 

Here's my function to get the final URL:

PHP Code:

function get_final_url($url){ 
    global $final_host; 
        $redirects = get_all_redirects($url); 
        if (count($redirects)>0){ 
          $final_url = array_pop($redirects); 
          if(substr($final_url,0,7) != 'http://' && !empty($final_host)) 
            { $final_url = 'http://'.$final_host.$final_url; } 
                return $final_url; 
        } else { 
                return $url; 
        } 

Here's the cURL execution:

 

$ch2 = curl_init();      
                        curl_setopt($ch2,CURLOPT_URL,$url); 
                        curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); 
                        curl_setopt($ch2,CURLOPT_POST,''); 
                        curl_setopt($ch2,CURLOPT_POSTFIELDS,''); 
                        curl_exec($ch2); 
                        curl_close($ch2); 

 

For some reason, this works no problem, posts any data over to the URLs serverside, redirects serverside, and passes the client to the final URL, with none of the redirection displayed via HTTPWatch or any similar debug utility. Sometimes, however, it does show phases of redirection.

 

Any insight into what I might be doing incorrectly?

 

Thanks SO much in advance.

E

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.