json - Parse response and response headers PHP -
i'm working on app supposed status , date account created. have response (in json format) can't seem parse neither response nor response headers. don't show echo. extract 2 variables of response , since response header delivers cookie, , store next response. here response received:
http/1.1 100 continue http/1.1 200 ok date: fri, 27 jun 2014 14:28:38 gmt server: apache set-cookie: ci_session=one_very_long_cooooookie; expires=fri, 27-jun-2014 16:28:38 gmt; path=/ status: 200 content-length: 304 content-type: application/json { "success": true, "user": { "user_id": "2k287as952", "username": "myusername", "requesting_ip": "123.456.789.012", "account_created_at": "2012-08-13 15:57:35", "online_status": "1", "auth_token": "26cc3bcf-2cb5-a90e-b1ca-76d40c34e097" } }
now here have been trying response header per php docs should give me "set cookie" variable comes empty. post .php file here if need be.
edit tried curl , i'm getting response. here code i'm trying. how parse response get
thanks in advance
<?php //set variables ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); $url = 'http://webpage.api.com'; $data = http_build_query( array('password' => 'myfunkypassword', 'email' => 'some_email@gmail.com') ); $curl = curl_init(); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_httpget, true); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_verbose, true); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_postfields, $data); curl_setopt($curl, curlopt_header, true); curl_setopt($curl, curlopt_httpheader, array( 'content-type: application/x-www-form-urlencoded', 'user-agent: dalvik/1.6.0 (linux; u; android 2.3.3; htc pyramid build/gri40)', 'host: api.hackex.net', 'expect: 100-continue', 'host: api.hackex.net' )); $result = curl_exec($curl); print_r($result); //~ // limite positivo //~ $header_size = curl_getinfo($curl, curlinfo_header_size); //~ $header = substr($result, 0, $header_size); //~ $body = substr($result, $header_size); //~ list($header, $body) = explode("\r\n\r\n", $result, 2); echo curl_getinfo($curl, curlinfo_http_code); curl_close($curl); ?>
var req = $.ajax({ url:___, type:___, data:____, datatype:____, cache:false }); req.done(function(data){ // parse response stored in data var parseddata = json.parse(data); });
this skeleton. included needed values
Comments
Post a Comment