I have a question:
If I set cURL to include header information in the output, how do I extract just the PHPSESSID information from that output?
The output looks something like that:
OUTPUT: HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Wed, 26 Sep 2011 19:10:48 GMT Server: Apache/2.2.16 (Win32) mod_ssl/2.2.16 OpenSSL/0.9.8o X-Powered-By: PHP/5.3.5 Set-Cookie: PHPSESSID=lsa18d8r126ps1vfp4h05dh8r4; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Transfer-Encoding: chunked Content-Type: text/html
This is a very simple solution, I don’t know if there is any curl way to retrieve that, but it can be handled with a simple regexp.
If the string is syntactically the same for every request you can do it as shown.
The “;” which marks the end of the session id is mandatory, else the regexp fails and returns the whole string, because it did not match. Maybe you should use a
preg_matchin front of a extraction to make sure it is syntactically correct or even there exists aPHPSESSIDin the string.