How to keep current JSESSIONID on multiple request calls?
i am trying to keep current session id but i am failing. I have 2 separate
methods that call the same method
i.e.
$foo1->method
$foo2->method
inside the method there is cURL for sending data to servlet. What is
happening at the moment is that each request call generates new session
id, and thats not good. How do i keep set session id once and keep on
reusing it ??
Code below:
public function curlWithID($url, $value){
echo "session has id";
}
public function curlWithoutID($url, $value){
Global $result;
$m = array();
$size = sizeof($m);
if(isset($_SESSION['JSESSIONID'])? : null){
$this->curlWithID($url, $value);
}
else{
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
session_write_close();
$ch = curl_init();
//Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $value);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
if(preg_match('/Set-Cookie: JSESSIONID=(.*?);/', $result, $m))
{
//set cookie
$_SESSION['JSESSIONID'] = $m[1];
echo $m[1];
}
}
This is my attempt so far. Help appreciated, thanks
No comments:
Post a Comment