User talk:Patrick Nagel/Login with snoopy post-1.15.3

Be independent of the cookie name
Instead of:
 * $snoopy->cookies["wiki_session"] = $response[login][sessionid];

I used:
 * $snoopy->cookies = getCookieHeaders($snoopy->headers);

and the function getCookieHeaders is: function getCookieHeaders($headers){ $cookies = array; foreach($headers as $header) if(preg_match("/Set-Cookie: ([^=]*)=([^;]*)/", $header, $matches)) $cookies[$matches[1]] = $matches[2]; return $cookies; }
 * 1) This function parses Snoopy's header array and returns a nice array of cookies

It works better because you don't have to know the name of the cookie in advanced. (I took the function from http://www.mail-archive.com/mediawiki-api@lists.wikimedia.org/msg00099.html)
 * Thanks, I added a link to your proposal. --Patrick Nagel 02:38, 23 July 2010 (UTC)

Trim whitespace from Snoopy results before passing to unserialize
Instead of: $response = unserialize($snoopy->results); I used: $response = unserialize(trim($snoopy->results));

I was getting a simple error and it had a simple solution. I didn't take the time to figure out how whitespace was getting into my API results. Here is where it came from: http://www.microtuts.com/php-unserialize-error-at-offset-simple-solution/.