[Pro] PHP, cURL and Cookies

Thanks for the link, Tim, but I don’t understand what those -b, -c, -d switches do. (They are mentioned in the code presented on the StackOverflow link you provided.)

So I Googled and tried some other code, but without success:

<?php
    ini_set('display_errors', true);
    error_reporting(E_ALL);
	
    session_start(); 
    $strCookie = 'JSESSIONID=' . $_COOKIE['fmi-cookie'] . '; path=/'; 
    session_write_close(); 
	
    $curl = curl_init();

    curl_setopt($curl, CURLOPT_COOKIE, $strCookie );     
    curl_setopt ($curl, CURLOPT_URL, "http://hartford.macusa.net/fmi/iwp/cgi?-db=Install_Info.fp7&-startsession");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec ($curl);
    curl_close ($curl);
    print $result; 
?>

The above code results in the following error:

Notice: Undefined index: fmi-cookie in /home/jdwages/domains/kiramek.com/public_html/curl_FMDB-LoginPage_test.php on line 6

I then tried this code:

<?php
    ini_set('display_errors', true);
    error_reporting(E_ALL);
    $curl = curl_init();
    
    curl_setopt($curl, CURLOPT_COOKIEJAR, "fmi-cookie");  // Initiates cookie file if needed 
    curl_setopt($curl, CURLOPT_COOKIEFILE, "fmi-cookie");  // Uses cookies from previous session if exists 
    curl_setopt($curl, CURLOPT_VERBOSE, 1); 
    curl_setopt($curl, CURLOPT_HEADER, 1); 
    
    curl_setopt ($curl, CURLOPT_URL, "http://hartford.macusa.net/fmi/iwp/cgi?-db=Install_Info.fp7&-startsession");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    
    $result = curl_exec ($curl);
    curl_close ($curl);
    print $result; 
?>

But that yields this error:

HTTP/1.1 302 Moved Temporarily 
Date: Mon, 13 Jul 2015 08:10:44 GMT 
Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET 
Date: Mon, 13 Jul 2015 08:10:44 GMT 
Server: hartford.macusa.net Cache-control: no-cache="set-cookie" Cache-control: must-revalidate 
Set-Cookie: JSESSIONID=054FC374C75DA594156C9FC8.wpc1; 
Path=/fmi/iwp; Version=1 Set-Cookie: fmi-cookie=fmi-cookie; Path=/; 
Version=1 Content-Type: text/html; charset=utf-8 
Location: http://hartford.macusa.net/fmi/iwp/res/iwp_auth.html;jsessionid=054FC374C75DA594156C9FC8.wpc1 
Content-Length: 0 
Expires: Tue, 03 May 1988 14:40:00 GMT

Casting PHP aside and opening the URL directly in Safari shows the following in Safari’s Console:

http://cl.ly/image/2S2P192w3C1V

URL:
http://hartford.macusa.net/fmi/iwp/cgi?-db=Install_Info.fp7&-startsession

I’m about as lost as I can be!

–James W.


dynamo mailing list
email@hidden
Update your subscriptions at: