curl - Send cookies via HttpRequest in PHP along with request -


i've got pbx server (asterisk 1.8), , i'm able manage calls via variables in request. issue need first login server. once i've done want save cookie, , send along verification along next requestion.

i have code works using curl:

public function authenticate(){     $temp_dir = sys_get_temp_dir();     $ckfile = tempnam($temp_dir, "ast");      $auth_url = $this->ast_link."?action=login&username=asterisk_http&secret=*****";      $ch = curl_init();     curl_setopt($ch, curlopt_url, $auth_url);     curl_setopt($ch, curlopt_header, 0);     curl_setopt ($ch, curlopt_cookiejar, $ckfile);     curl_setopt($ch, curlopt_useragent, "mozilla");     curl_setopt($ch, curlopt_returntransfer, 1);     $auth_response = curl_exec($ch);     curl_close($ch);     $this->auth_cookie = $ckfile;     return $ckfile; } //$call contains id, patcode, phone_number, call_type public function makecall($overload, $call, $exten, $user = null){     set_time_limit(0);      if(!$this->auth_cookie) $this->authenticate();             //http://blah.server/asterisk/rawman?action=originate&channel=$somechannel     $call_url = $this->generatecallurl($overload, $call, $exten, $user);      $ch = curl_init();     curl_setopt($ch, curlopt_url, $call_url);     curl_setopt($ch, curlopt_header, 0);     curl_setopt($ch, curlopt_failonerror, 1);     curl_setopt($ch, curlopt_cookiefile, $this->auth_cookie);     curl_setopt($ch, curlopt_returntransfer, 1);     $response = curl_exec($ch);     curl_close($ch);      return $response; } 

unfortunately curl waits response server, happens @ end of call. because of i'm unable make multiple calls simultaneously.

how use httprequest in php send cookie along request in same way curl does? i'm little unfamilliar networking mechanics behind this, forgive me ignorance on this.

tl;dr: how send cookie along httprequest

as far question concerned on "how send cookie along httprequest" think might able because have solved similar problem.

first thing's first, whenever want know going on @ network level i.e type of requests coming , type being sent, network tab in chorme console. alternatively can download , install firebug monitor incoming , outgoing requests (these tips in next project).

and setting cookies via http header use following php code.

header('set-cookie: cookiename='.$content); 

here cookie name name of session cookie i.e jsessionid etc , content related key has shouted every time client needs authenticated.

i hope information , other developers :)


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -