Plugin Directory

Changeset 1458487


Ignore:
Timestamp:
07/21/2016 07:12:47 PM (10 years ago)
Author:
clickfunnels.com
Message:

Follow redirects on curl request.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • clickfunnels/trunk/clickfunnels.php

    r1458486 r1458487  
    9393    public function get_page_content( $url ) {
    9494        $ch = curl_init();
    95         curl_setopt($ch, CURLOPT_URL, $url);
    9695        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    9796        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    98         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    99 
    100         // Get http header for cookies
    101         curl_setopt($ch, CURLOPT_VERBOSE, 1);
     97        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    10298        curl_setopt($ch, CURLOPT_HEADER, 1);
    10399
     
    111107        curl_setopt( $ch, CURLOPT_COOKIE, implode(';', $cookies) );
    112108
    113         // Stop session so curl can use the same session without conflicts
    114         session_write_close();
    115 
    116         $response = curl_exec($ch);
     109        $destination = $url;
     110
     111        while ($destination) {
     112            session_write_close();
     113            curl_setopt($ch, CURLOPT_URL, $destination);
     114            $response = curl_exec($ch);
     115            $curl_info = curl_getinfo($ch);
     116            $destination = $curl_info["redirect_url"];
     117            session_start();
     118        }
    117119        curl_close($ch);
    118120
    119         // Session restart
    120         session_start();
    121 
    122         // Seperate header and body
    123         list($header, $body) = explode("\r\n\r\n", $response, 2);
    124 
    125         // Extract cookies form curl and forward them to browser
    126         preg_match_all('/^(Set-Cookie:\s*[^\n]*)$/mi', $header, $cookies);
     121        $headers = substr($response, 0, $curl_info["header_size"]);
     122        $body = substr($response, $curl_info["header_size"]);
     123
     124        // Extract cookies from curl and forward them to browser
     125        preg_match_all('/^(Set-Cookie:\s*[^\n]*)$/mi', $headers, $cookies);
    127126        foreach($cookies[0] AS $cookie) {
    128127            header($cookie, false);
Note: See TracChangeset for help on using the changeset viewer.