Forum Moderators: coopster

Message Too Old, No Replies

php curl problems with set cookie

         

samdyk

9:24 am on Jun 10, 2008 (gmt 0)

10+ Year Member



hi all forum user,

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

PHP_Chimp

10:02 am on Jun 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CURLOPT_FOLLOWLOCATION [uk.php.net], otherwise you dont follow any Location headers returned.

samdyk

8:37 am on Jun 11, 2008 (gmt 0)

10+ Year Member



i add this line to my code

curl_setopt($cobj,CURLOPT_FOLLOWLOCATION,true);

but it still not diplay cookie

any other issues

PHP_Chimp

8:47 pm on Jun 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hummmmmm....

Try adding CURLOPT_HEADER, true to your options. Then you should be able to see the header as well. That may throw some light on the problem.

samdyk

2:34 am on Jun 12, 2008 (gmt 0)

10+ Year Member



yes after i add this line

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]

PHP_Chimp

9:33 am on Jun 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the output on the viewCookie.php page? Is it just completely blank?

samdyk

10:10 am on Jun 13, 2008 (gmt 0)

10+ Year Member



yes the output of viewCookie.php page is completely blank

i don know why?