want the value cookie that i got from the following code further used in php script to visit next url because value of cookie used in url ....how i can save value of cookie and again use it in my php script

suppose cookie is JSESSIONID GT1~A555400D38C7F737D383DEEBA8A30CE3.GT.1
and my next url is
http://www.url.com/q.action?id=A555400D38C7F737D383DEEBA8A30CE3.GT.1

<?php
$cookie=tempnam("/tmp","CURLCOOKIE");
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $login);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $login);
$html=curl_exec($ch);

?>

Recommended Answers

All 4 Replies

First time you set CURLOPT_COOKIEJAR, for rest of all calls, use same name with option CURLOPT_COOKIEFILE.

<?php
$cookie=tempnam("/tmp","CURLCOOKIE");
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $login);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $login);
$html=curl_exec($ch);

$ch = curl_init();
$nexturl=http://www.url.com/q.action?id=A555400D38C7F737D383DEEBA8A30CE3.GT.1"
curl_setopt($ch, CURLOPT_URL, $nexturl);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $nexturl;
$html=curl_exec($ch);




?>

Thanks Friend for helping me....my problem is id=(.?) ......(.?) is a value of cookie ...my question is how i open cookie file and get cookie value and then i am able to visit next url

Cookie is passed from server, when u set cookiejar, you are specifying cookie file for that session,
to request other things in same session, the curl must know the session cookie, so all next time we use cookiefile option to read same cookie file.

Nothing to do with id and all

bro A555400D38C7F737D383DEEBA8A30CE3.GT.1 is a cookie value which always changed..it does not remains A555400D38C7F737D383DEEBA8A30CE3.GT.1 ...how can i capture it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.