Topic: "Extracting response cookies" (page 1 of 1)

1
Author Post
velo
groupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmaster
PHP question:
Does anyone know how to extract cookies from response header and send them again to the same page , but with some POST data?
Cookies are changed every time when I try to open it.
This is a scenario/pseudocode:
1. Open a page
2. Page set new cookies
2. Read cookies from response header
3. Open again the same page and send new cookies.
private message
aceldama
groupmastergroupmastergroupmastergroupmaster
look at the header information using live headers?
private message
velo
groupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmaster
That's OK, but I need to get it through PHP code...
private message
aceldama
groupmastergroupmastergroupmastergroupmaster
let me see whether i understand the question first. from what i understand is that you want to request the page, then re-submit the form with the cookie the server sent you in the header along with some other data? if this is the case i think you'd be better off using ajax's HTTPRequest method in a browser script instead of php.
private message
Towley
groupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmaster
i dont think its possible to request a new page via php.

to set a cookie you use something like set_cookie();
and to read the cookie you use $_COOKIE["cookiename"];

to re-request the page, you could use javascript, or meta-tags, but i guess you can avoid to re-request the page somehow.

greets
Towley
private message Website
sniperkid
groupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmaster
Maybe try using javascript in the header like javascript:alert(document.cookie.name); and javascript:void() to change it and just reload the page?

private message Website
S0410N3
groupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmastergroupmaster
You can use sockets directly or php_curl.

With php_curl it's pretty easy. By activing the CURLOPT_HEADER option, you'll get the header with the page.

$url="http://www.google.com/";
$curl= curl_init () ;
curl_setopt($curl ,CURLOPT_URL,$url);
curl_setopt($curl ,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl ,CURLOPT_HEADER,true);
$page=curl_exec($curl);
curl_close($curl) ;

echo $page;

After this you have to extract the cookie value from the header which is included in $page with a regexp for example (Set-Cookie:...), then call another page sending this cookie :

$url="http://www.google.com/";
$curl= curl_init () ;
curl_setopt($curl ,CURLOPT_URL,$url);
curl_setopt($curl ,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl ,CURLOPT_COOKIE,$mycookie);
$page=curl_exec($curl);
curl_close($curl) ;

Take a look at linkhttp://fr.php.net/manual/fr/function.curl-setopt.php for more options you can use with curl, like for example sending POST vars.

Edit : Nevermind I didn't see your question was also refering to POST vars.

You just have to add in the options :
curl_setopt($curl ,CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);

where $data is an associative array :
$data=array("var1"=>"value1", "var2"=>"value2",...);
Edited by S0410N3 on 30.05.2008 11:44:56
private message Website

Topic: "Extracting response cookies" (page 1 of 1)

1