Forum Moderators: coopster
i want to make http request thought curl extension in php 5 but it has problem with setcookie.
client.php (is under 192.168.2.122 server)
----------------------------------------------------------------------
<?php
$rs = "http://192.168.2.105/setCookie.php";
$header = array("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
"Accept-Language: en-us,en;q=0.5",
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 300",
"Connection: keep-alive");
$uri = $rs;
$cobj = curl_init($uri);
curl_setopt($cobj,CURLOPT_HTTPHEADER,$header);
curl_setopt($cobj,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14");
curl_setopt($cobj,CURLOPT_ENCODING,"");
curl_setopt($cobj,CURLOPT_RETURNTRANSFER,1);
$xml = curl_exec($cobj);
curl_close($cobj);
echo $xml;
?>
---------------------------------------------------------------------
and i have files
setCookie.php (is under 192.168.2.105 server)
---------------------------------------------------------------------
<?php
setcookie("name","realwat");
header("Location: [192.168.2.105...]
?>
---------------------------------------------------------------------
viewCookie.php (is under 192.168.2.105 server)
---------------------------------------------------------------------
<?php
echo $_COOKIE['name'];
?>
---------------------------------------------------------------------
problem:
- i can't see cookie value when i access this [192.168.2.122...]
but if i access through this
[192.168.2.105...] i can see the cookie is set and displayed on the browser
thanks
curl_setopt($cobj,CURLOPT_FOLLOWLOCATION,true);
when i acces i see the http header and also in http header Set-Cookie there is value name=realwat but on the page that i view through $_COOKIE['name']; there still no result.
here is the http header
------------------------------------------------------------------------
HTTP/1.1 302 Found Date: Thu, 12 Jun 2008 01:18:20 GMT Server: Apache/2.2.3 (Debian) PHP/5.2.0-8+etch10 mod_ssl/2.2.3 OpenSSL/0.9.8c X-Powered-By: PHP/5.2.0-8+etch10 Set-Cookie: name=realwat Location: http://example.com/viewCookie.php Content-Length: 0 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html HTTP/1.1 200 OK Date: Thu, 12 Jun 2008 01:18:20 GMT Server: Apache/2.2.3 (Debian) PHP/5.2.0-8+etch10 mod_ssl/2.2.3 OpenSSL/0.9.8c X-Powered-By: PHP/5.2.0-8+etch10 Content-Length: 27 Keep-Alive: timeout=15, max=99 Connection: Keep-Alive Content-Type: text/html
any more hints
thanks
[edited by: coopster at 1:41 am (utc) on June 13, 2008]
[edit reason] changed to example.com [/edit]