Author | Post | ||
velo |
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. |
||
24.05.2008 11:51:15 |
|
||
aceldama |
look at the header information using live headers? |
||
24.05.2008 23:50:20 |
|
||
velo |
That's OK, but I need to get it through PHP code... |
||
26.05.2008 10:20:05 |
|
||
aceldama |
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. |
||
27.05.2008 15:40:40 |
|
||
Towley |
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 |
||
27.05.2008 19:58:40 |
|
||
sniperkid |
Maybe try using javascript in the header like javascript:alert(document.cookie.name); and javascript:void() to change it and just reload the page? |
||
28.05.2008 06:56:50 |
|
||
S0410N3 |
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 http://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 | |||
30.05.2008 11:36:52 |
|