Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get Cookies from Php Curl into a variable?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 17.6k
    Comment on it

    Hello readres, today we discuss about "Get Cookies from Php Curl into a variable?".

    CURL provides an option (CURLOPT_RETURNTRANSFER) to set a callback that will be called for each response header line. The function will receive the curl object and a string with the header line.

    <?php
    
    $ch = curl_init('http://www.google.com/');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    curl_setopt($ch, CURLOPT_HEADER, 1);
    $result = curl_exec($ch);
    
    preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);        // get cookie
    $cookies = array();
    foreach($matches[1] as $item) {
        parse_str($item, $cookie);
        $cookies = array_merge($cookies, $cookie);
    }
    var_dump($cookies);
    
    
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: