[Pro] PHP, cURL and Cookies

I was advised by someone off-list to rewrite the HEADER in an attempt to deal with JSESSIONID. I save the HEADER and COOKIE into the root/tmp/ directory, which has 777 permissions. Here’s the code:

<?php
    ini_set('display_errors', true);
    error_reporting(E_ALL);
    $headerfile = 'root/tmp/headers.txt';
    $cookiefile = 'root/tmp/fmi-cookie.txt';
    $useragent = $_SERVER['HTTP_USER_AGENT'];
    $cookies = $_SERVER['HTTP_COOKIE'];
 
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_URL, "http://hartford.macusa.net/fmi/iwp/cgi?-db=Install_Info.fp7&-startsession");
    curl_setopt($curl, CURLOPT_COOKIE, $cookies);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_WRITEHEADER, fopen($headerfile, 'w+'));
    $result = curl_exec ($curl);
 
    curl_close ($curl);
 
    $headers = file($headerfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach($headers as $header){
        header($header);
    }
    print $result;
?>

I fully understand that I don’t need to name my cookie the same as what is used by FM IWP, but there’s no harm in it and it helps my brain know better what it is. The content of “fmi-cookie.txt” saved into root/tmp/ when I execute the above script is as follows:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

hartford.macusa.net	FALSE	/fmi/iwp	FALSE	0	JSESSIONID	0573C320F091469D15509EA4.wpc1
hartford.macusa.net	FALSE	/	FALSE	0	fmi-cookie	fmi-cookie

And the content of “headers.txt” saved into root/tmp/ when I execute the above script is as follows:

HTTP/1.1 302 Moved Temporarily
Date: Tue, 21 Jul 2015 08:28:01 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 21 Jul 2015 08:28:01 GMT
Server: hartford.macusa.net
Cache-control: no-cache="set-cookie"
Cache-control: must-revalidate
Set-Cookie: JSESSIONID=0573C323F0A0574D15509EA7.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=0573C323F0A0574D15509EA7.wpc1
Content-Length: 0
Expires: Tue, 03 May 1988 14:40:00 GMT

Executing the PHP script in-browser displays the “You have logged out.” page at /iwp_home.html on my FileMaker server, rather than displaying the Login page (I want the Login page). I was told that I would need to “write a proxy in PHP” to resolve the problem.

What are your thoughts on this?

Thanks,

James W.


dynamo mailing list
email@hidden
Update your subscriptions at: