** not really a modx question, well sort of, but right now more of a Curl/Php question that I would love some help with - BTW this is cross posted on moodle.org and in stackexchange if anyone wants to snare a few rep points

**
I'm trying to write a SSO plugin for Modx so that users logging into modx also get a Moodle session, I think the easiest way to do that would be to use curl, retrieve the session cookies from moodle and set them in the background in a modx plugin.
After a bit of googling & curl docs here is where I got to:
$username = 'user';
$password = 'pass';
$ckfile = tempnam ("/tmp", "CURLMOODCOOKIE");
//set POST variables
$url = 'host.com/login/index.php';
$fields_string = 'username='.$username.'&password=';
$fields_string .=$password.'&rememberusername=1&Login';
rtrim($fields_string, '&');
echo $fields_string.'
';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch,CURLOPT_AUTOREFERER, true );
//execute post
$content = curl_exec($ch);
$response = curl_getinfo( $ch );
echo 'response=';
print_r($response);
echo 'content='.$content;
//close connection
curl_close($ch);
So far it works, it writes a file in the /tmp directory with some cookie information:
host.com FALSE / FALSE 0 MoodleSession qbujmcc2roc6q2fvsjevv7h2j6
host.com FALSE / FALSE 1351394923 MOODLEID1_ %25E5%25B2z%25E40j%25DD%25BDYZh
So now all I should have to do is add an expiration date to the MoodleSession cookie & then pass both cookies back to the user's browser - correct? - which is where I am getting lost:
Is there a nice handy way to extract the cookie data as an array or just "pass" it back to the browser? Or will I have to figure out some regexp to extract that stuff and set it VIA php?