PHP - 2 Responses In The Same Response?
Hello All, running into a situation that I have not seen before. I have been seeing in multiple areas of my application that the response received from the server has 2 JSON responses in it. Here is a sample function:
private function getCatalogItems(){ $start = ($_REQUEST["start"] == null)? 0 : $_REQUEST["start"]; $count = ($_REQUEST["limit"] == null)? 20 : $_REQUEST["limit"]; $q = "SELECT c.`id`, c.`catalog_number`, c.`long_description`, CONCAT(c.`catalog_number`, ' - ', c.`long_description`) AS `display` FROM catalog c"; if(!empty($_REQUEST['query'])){ $q .= " WHERE c.`catalog_number` LIKE '%".$_POST['query']."%'"; } $q .= " ORDER BY c.`catalog_number` ASC LIMIT ".$start.",".$count; $rs = $this->db->get_results($q); $total = $this->db->num_rows; $buff = '{"total":"'.$total.'","data":'.json_encode($rs).'}'; $this->c->returnJSON($buff); } The "returnJSON" function looks like this. public function returnJSON($json){ $contentType = "application/json; charset=utf-8"; header("Content-Type: {$contentType}"); header("Content-Size: " . strlen($json)); echo $json; } As you can see this simply sets the headers of the response. It has been a real head scratcher. Anyone come across something like this before? Similar TutorialsA HTTP request is made to the server, Slim creates a Request and Response object, content in the Request is sent to another server using cURL via Guzzle, Guzzle returns its own Response, and content from Guzzle's response must be returned by the original Slim response. Would you recommend white-listing or black-listing response headers, and which specific headers? Similarly, would you recommend white-listing or black-listing the request headers sent via cURL, and which specific headers? Thanks <?php use Psr\Http\Message\ResponseInterface as Response; use GuzzleHttp\Psr7\Response as CurlResponse; class ApiResponder { public function delete(Response $httpResponse, CurlResponse $curlResponse) { return $this->proxy($httpResponse, $curlResponse); } //other public methods... private function proxy(Response $httpResponse, CurlResponse $curlResponse) { foreach($this->getResponseHeaders($curlResponse) as $name=>$value) { $httpResponse=$httpResponse->withHeader($name, $value); } return $httpResponse->withBody($curlResponse->getBody())->withStatus($curlResponse->getStatusCode()); } private function getResponseHeaders(Response $httpResponse):array { //Blacklist headers which should be returned to original client. TBD whether I should whitelist headers instead. $blacklist=['Date'=>null, 'Server'=>null, 'X-Powered-By'=>null, 'Access-Control-Allow-Origin'=>null, 'Access-Control-Allow-Methods'=>null, 'Access-Control-Allow-Headers'=>null, 'Set-Cookie'=>null]; return array_diff_key($curlResponse->getHeaders(), $blacklist); } /** * This method doesn't really exist in this class, but is just included to show which headers I am forwarding in the cURL request. */ private function getRequestHeaders($clientRequest):array { $whitelist=['connection'=>null,'accept'=>null,'accept-encoding'=>null,'accept-language'=>null,'content-type'=>null,'content-length'=>null]; return array_intersect_key($clientRequest->getHeaders(), $whitelist); } }
I am using Guzzle as a HTTP client, and the following script results in the following error: $response = $this->httpClient->request('GET', "http://$this->host:$this->port/query", ['query' => $data]); $body = $response->getBody(); $rs=json_decode($body, true); Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 136956008 bytes) in /var/www/vendor/guzzlehttp/psr7/src/Stream.php on line 80 What are the work arounds? Instead of trying to convert it into an array all at once, how can I do so in pieces? I know the expected format so it seems I will need to read just the appropriate amount of bytes and then decode parts at a time. Seems like a pain. Are there any classes designed to do so, or can any of the following Guzzle built in methods be used? Thanks Guzzle Response methods: __construct getStatusCode getReasonPhrase withStatus getProtocolVersion withProtocolVersion getHeaders hasHeader getHeader getHeaderLine withHeader withAddedHeader withoutHeader getBody withBodyGuzzle Body methods: __construct __destruct __toString getContents close detach getSize isReadable isWritable isSeekable eof tell rewind seek read write getMetadataI have the following tables: department id course id department_id CASCADE DELETE student id student_courses course_id CASCADE DELETE student_id CASCADE DELETEI also have the following REST API endpoints: DELETE department/123 (deletes targeted department and associated courses as well as the list of students in the course) DELETE course/321 (deletes targeted course as well as the list of students in the course) DELETE student/111 (deletes targeted student as well as the list of students in the course)The user should be informed before deleting a given record if that record will affect other tables. For instance, if deleting a department which has some courses or deleting a student which belows to a course. One option is to respond to DELETE department/123 with 400 {recordUsed: {courses:[bla, bla], student_courses:[bla, bla]}} if used. For this option, the client would then prompt the user of the implications and if desired repeat the request but include a "force" parameter of TRUE in the request which will delete the record regardless of being used. Another option is to add some new endpoints which will return the resources which are associated with the to be deleted entity. If empty, a DELETE request would automatically be made and if not empty the user will first be prompted whether the DELETE request should be made and the server would delete the record(s) regardless of being used. GET department/utilized/123 GET course/utilized/321 GET student/utilized/111Any thoughts on which approach should be used? Or maybe some other strategy? Thanks How to make a form using HTML/PHP with conditional responses based on zip code? What I want to do exactly... zip codes 91900-92600 go to URL www.example.com after submit. All others go to URL www.example.com/page after submit. Any help would be much appreciated. Hi everyone... I would like to implement a questionnaire/survey system that has only two Answers (Yes /No). Basically, this questionnaire system will be widely used on Mobile Phones. It will be looking something like this below: http://awardwinningfjords.com/2009/06/16/iphone-style-checkboxes.html Lets say a user selects a response as No (Using the above slider button for a question). That response should be recorded in the database with User Details + Time Stamp. Also, I would like to generate a report for each question (Responses of Multiple Users) and a report at a User Level for the entire questionnaire/survey (s). Can some one guide me the fastest & easiest way to achieve this? I'm a new learner of PHP. Regards Sandeep When I submit the login form its not returning anything and it was working until I added in the $remember part so I'm wondering why its still not returning TRUE. Code: [Select] /** * Login user on the site. Return TRUE if login is successful * (user exists and activated, password is correct), otherwise FALSE. * * @param string * @param string * @param int * @return bool */ function login($username, $password, $remember) { $this->ci->load->model('kow_auth/users'); $user_data = $this->ci->users->get_user_by_username($username); if ($user_data) { $regenFromPostPW = $this->ci->genfunc->reGenPassHash($password, $user_data->password2); if ($regenFromPostPW == $user_data->password) { $this->ci->session->set_userdata(array( 'xtr' => 'yes', 'user_id' => $user_data->user_id, 'username' => $user_data->username, 'status' => $user_data->users_statuses_id, 'role' => $user_data->users_roles_id )); if ($remember == 1) { $timeTOexpire = time()+(60*60*24*31*2); $this->input->set_cookie('xtrcook', '1', $timeTOexpire); } else { $cookie = trim(get_cookie('xtrcook')); if ($cookie || is_numeric($cookie)) { delete_cookie('xtrcook'); } } $this->clear_login_attempts($user_data->user_id); $this->ci->users->insert_session($this->ci->session->userdata('session_id'), $this->ci->session->userdata('user_id'), $this->ci->genfunc->getRealIpAddr(), $this->ci->genfunc->getUserOS()); return TRUE; } else { $this->increase_login_attempt($user_data->user_id); } } else { return NULL; } } Folks, I have a mysql tbl called "links". In it a column named "keywords". The row 0 has a keyword "search" in the "keywords" column. I am doing a search for the words "search" in the html form. Clicking the button gives no response! What is wrong ? I get no mysql connection error. Nor any php error. So it should work and respond! <form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <input type="button" name="search_links" id="search_links" value="Search Links!"> <br> <input type="reset"> <br> </form>
Full short code ... <?php //include('error_reporting.php'); ini_set('error_reporting','E_ALL');//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); ?> <form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <input type="button" name="search_links" id="search_links" value="Search Links!"> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['search_links'])) { if(ISSET($_POST['keywords'])) { $keywords = $_POST['keywords']; } mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $conn = mysqli_connect("localhost","root","","test"); $db_server = 'localhost'; $db_user = 'root'; $db_password = ''; $db_database = 'test'; $conn->set_charset('utf8mb4');//Always use Charset. if (!$conn) { //Error Message to show user in technical/development mode to see errors. die("Database Error : " . mysqli_error($conn)); //Error Message to show User in Layman's mode to see errors. die("Database error."); exit(); } $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$keywords); $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); mysqli_stmt_execute($stmt); mysqli_stmt_fetch($stmt); while(mysqli_stmt_fetch($result)) { echo "url"; echo "<br>"; echo "anchor_text"; echo "<br>"; echo "description"; echo "<br>"; echo "keyphrases"; echo "<br>"; echo "keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { echo "1. QUERY failed!"; } if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$keywords); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); while($row = mysqli_fetch_array($result,mysqli_assoc)) { $page_url = $row['page_url']; echo $page_url; echo "<br>"; $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>"; $page_description = $row['page_description']; echo $page_description; echo "<br>"; $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>"; $keywords = $row['keywords']; echo $keywords; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("2. QUERY failed!"); } } } ?> Hello, I'm trying to get webservice response in xml format. I'm getting the response but it's not in xml. It's just text. Can someone please look at the code ? <?php $targeturl="https://api.com"; $DevKey= "xxxxx"; // return xml feed $ch = curl_init($targeturl); curl_setopt($ch, CURLOPT_POST, FAlSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$DevKey)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch); $xml = new SimpleXMLElement($response); curl_close($ch); echo $response; // will print in browser all country codes in an xml format /* ADD YOUR OWN CODE HERE TO DO WHAT YOU WANT WITH THE RESPONSE. MAYBE SAVE RESULTS TO A FILE OR THE PARSE THE RESULTS INTO A DATABASE? */ ?> I send off this: <?php $data = "<egateway> <eCardExpiryMonth>01</eCardExpiryMonth> <eCardExpiryYear>04</eCardExpiryYear> <eCardHoldersName>Joe Bloke</eCardHoldersName> <eCardNumber>4444333322221111</eCardNumber> <eCVN>123</eCVN> <eTotalAmount>100</eTotalAmount> </egateway> "; $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $edata); curl_setopt($ch, CURLOPT_URL, "https://www.example.com/gateway_cvn/testpage.asp"); curl_exec($ch); curl_close($ch); ?> In return, I get the following XML: Code: [Select] <eResponse> <eTrxnStatus>True</eTrxnStatus> <eTrxnNumber>20219</eTrxnNumber> <eAuthCode>123456</eAuthCode> <eReturnAmount>100</eReturnAmount> <eTrxnError>00,Transaction Approved(Test CVN Gateway)</eTrxnError> </eResponse> Is there a way to make it so this does not show, and instead I can make PHP do something like: if (eTrxnStatus == True) {// do stuff}; ? How can I receive a response from the server with JSON data, when the function that retrieves the data and returns it to the browser has been completely commented out? I am making an AJAX request for JSON formatted data and for some reason it returns a response when it shouldn't as there is no function? Hello All, Just working with PHP's snap v1 functions I can use snmpget fine but snmpset produces the following error; Warning: snmpset() [function.snmpset]: No response from 192..... Code Code: [Select] <?PHP echo 'File started <br />'; $ip = '192.168.1.100'; echo 'Read:<br />'; $sysdescr = snmpget($ip, 'public', '.1.3.6.1.4.1.17095.3.4.0', 300); echo $sysdescr; echo 'Write Started:<br />'; snmpset("$ip", 'public', '.1.3.6.1.4.1.17095.4.7.2.0', 's', 'sam@samtwilliams.co.uk', 300); ?> Like i said the get works fine just the set does not. Does anyone have any ideas? Sam Hi
I'm having this issue, when i put an url who must show me records i have blank html page
<?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); require_once 'database_connection.php'; $post=array( 'limit'=>(isset($_REQUEST['rows']))?$_REQUEST['rows']:'', 'page'=>(isset($_REQUEST['page']))?$_REQUEST['page']:'', 'orderby'=>(isset($_REQUEST['sidx']))?$_REQUEST['sidx']:'', 'orden'=>(isset($_REQUEST['sord']))?$_REQUEST['sord']:'', 'search'=>(isset($_REQUEST['_search']))?$_REQUEST['_search']:'', ); $se =""; if($post['search'] == 'true'){ $b = array(); $search['like']=elements(array('utilizador','email'),$_REQUEST); foreach($search['like'] as $key => $value){ if($value != false) $b[]="$key like '%$value%'"; } $search['where']=elements(array('nome','utilizador','email'),$_REQUEST); foreach($search['where'] as $key => $value){ if($value != false) $b[]="$key = '$value'"; } $se=" where ".implode(' and ',$b ); } $query = mysql_query("select count(*) as t from utilizador".$se); if(!$query) echo mysql_error(); $count = mysql_result($query,0); if( $count > 0 && $post['limit'] > 0) { $total_pages = ceil($count/$post['limit']); if ($post['page'] > $total_pages) $post['page']=$total_pages; $post['offset']=$post['limit']*$post['page'] - $post['limit']; } else { $total_pages = 0; $post['page']=0; $post['offset']=0; } $sql = "SELECT idutilizador, nome, utilizador, telefone, email, password FROM utilizador ".$se; if( !empty($post['orden']) && !empty($post['orderby'])) $sql .= " ORDER BY $post[orderby] $post[orden] "; if($post['limit'] && $post['offset']) $sql.=" limit $post[offset], $post[limit]"; elseif($post['limit']) $sql .=" limit 0,$post[limit]"; $query = mysql_query($sql); if(!$query) echo mysql_error(); $result = array(); $i = 0; while($row = mysql_fetch_object($query)){ $result[$i]['id']=$row->idutilizador; $result[$i]['cell']=array($row->idutilizador,$row->nome,$row->utilizador,$row->telefone,$row->email,$row->password); $i++; } $json = new stdClass(); $json->rows=$result; $json->total=$total_pages; $json->page=$post['page']; $json->records=$count; echo json_encode($json); function elements($items, $array, $default = FALSE) { $return = array(); if ( ! is_array($items)){ $items = array($items); } foreach ($items as $item){ if (isset($array[$item])){ $return[$item] = $array[$item]; }else{ $return[$item] = $default; } } return $return; } ?>*Update It works if i put $result[$i]['cell']=array($row->idutilizador,$row->telefone,$row->email,$row->password);So i'm think it's because in $nome(ex: Luis Miguel) and $utlizador(ex Susana Maria) don't accept this (space between words) it is correct? Edited by alphasil, 19 January 2015 - 08:54 AM. Could i use curl to check api response time and if so how? Hello, I am needing to cache a json response from an API so I am not making requests on each load. I have come across some code that is suppose to accomplish this but, it seems to not be working and can't figure out as to why. I created the cache file with 777 but it doesn't write or read from that file when I echo out the results.
The code below is just what is suppose to get the contents and cache it. At the end I tried to print it so I can test it to see it prints the response from the cache file but, nothing and the cache file does exists.
This is the first time I have tried something like this so please be gentle.
// cachePath is name of the path and file used to store cached current conditions gathered from the API request $cachePath = "./cache/nowcast-cache.txt"; // URL to the API request $url = "http://api.wunderground.com/api/XXXXXXXXXXXX/geolookup/conditions/q/TX/mesquite.json"; date_default_timezone_set('America/Chicago'); /** * Request jobs from API * * Split the request into smaller request chunks * and then consolidate them into a single array to limit the API * requests. */ function api_request() { file_put_contents($cachePath, file_get_contents($url)); } /** * API Request Caching * * Use server-side caching to store API request's as JSON at a set * interval, rather than each pageload. * * @arg Argument description and usage info */ function json_cached_api_results( $cache_file = NULL, $expires = NULL ) { global $request_type, $purge_cache, $limit_reached, $request_limit; if( !$cache_file ) $cache_file = dirname(__FILE__) . $cachePath; if( !$expires) $expires = time() - 2*60*60; if( !file_exists($cache_file) ) die("Cache file is missing: $cache_file"); // Check that the file is older than the expire time and that it's not empty if ( filectime($cache_file) < $expires || file_get_contents($cache_file) == '' || $purge_cache && intval($_SESSION['views']) <= $request_limit ) { // File is too old, refresh cache $api_results = api_request(); $json_results = json_encode($api_results); // Remove cache file on error to avoid writing wrong xml if ( $api_results && $json_results ) file_put_contents($cache_file, $json_results); else unlink($cache_file); } else { // Check for the number of purge cache requests to avoid abuse if( intval($_SESSION['views']) >= $request_limit ) $limit_reached = " <span class='error'>Request limit reached ($request_limit). Please try purging the cache later.</span>"; // Fetch cache $json_results = file_get_contents($cache_file); $request_type = 'JSON'; } return json_decode($json_results); } print_r($json_results); Edited by Texan78, 20 December 2014 - 03:51 PM. It's been quite a while since I have coded in PHP and I am running into difficulties looping through the returned response from an API. I am pretty comfortable in my PHP skills, but for some reason I keep getting caught up trying to loop through the following... Many of the returns from the API include several more layers of Objects, the example below is about the most simplistic return from the API.
I'm sure I'm just missing something easy and any help or example code simply looping through and echoing each result would be greatly appreciated!! Ideally I would like to be able to loop through both of the scenarios below.
I did a var_dump on the response and here is what I get:
array (size=1) 'Body' => object(stdClass)[6] public 'userContext' => object(stdClass)[8] public 'convCred' => object(stdClass)[10] ... public 'valid' => boolean true public 'isPasswordExpired' => boolean false public 'cbId' => int 0083802121 public 'cnId' => int 1000545 public 'locale' => string 'en_US' (length=5) public 'tncVersion' => int 2 public 'applicationId' => string 'ECFDA1FDBC00270772870CDC1786FFED' (length=32) public 'cbConvCred' => object(stdClass)[9] ... public 'preferenceInfo' => object(stdClass)[7] ... public 'lastLoginTime' => int 1406729928 public 'loginCount' => int 282 public 'passwordRecovered' => boolean false public 'emailAddress' => string 'abc@123.com' (length=11) public 'loginName' => string 'TEST' (length=8) public 'userId' => int 15932274 public 'userType' => object(stdClass)[14] public 'userTypeId' => int 1 public 'userTypeName' => string 'normal_user' (length=11) public 'isConfirmed' => boolean falseIf I jsonencode and jsondecode the response this is what I get: object(stdClass)[13] public 'Body' => object(stdClass)[17] public 'userContext' => object(stdClass)[18] public 'convCred' => object(stdClass)[19] ... public 'valid' => boolean true public 'isPasswordExpired' => boolean false public 'cbId' => int 0083802121 public 'cnId' => int 1000545 public 'locale' => string 'en_US' (length=5) public 'tncVersion' => int 2 public 'applicationId' => string 'ECFDA1FDBC00270772870CDC1786FFED' (length=32) public 'cbConvCred' => object(stdClass)[20] ... public 'preferenceInfo' => object(stdClass)[21] ... public 'lastLoginTime' => int 1406729953 public 'loginCount' => int 283 public 'passwordRecovered' => boolean false public 'emailAddress' => string 'abc@123.com' (length=11) public 'loginName' => string 'TEST' (length=8) public 'userId' => int 15932274 public 'userType' => object(stdClass)[24] public 'userTypeId' => int 1 public 'userTypeName' => string 'normal_user' (length=11) public 'isConfirmed' => boolean false I have been using PHP CURL to obtain stock data... The URL is
https://trade.plus50...ntName=Facebook
Essentially, it is supposed to return date, time, and price of stock tick data
But it returns stuff like "HrCy/h6wsw4esLL+HrCzDh6wsw4esLMOHrCzDh6wsu4esLLeHrCy7h6wsu4esLL"
So... I would like to know, what is this format, and how do I decode it? Thanks
Here is the full response....
{"InstrumentName":"Facebook","InstrumentID":1350,"StartPointDate":"2014-12-19 20:42:45.837","LastPointDate":"2014-12-19 20:59:59.463","SellRate":"MuHrCzHh6wsx4esLMuHrCzHh6wsy4esLMuHrCzLh6wsy4esLMuHrCzLh6wsz4esLMuHrCzDh6wsw4esLMOHrCzDh6wsv4esLMOHrCzDh6wsw4esLL+HrCy/h6wsw4esLL+HrCzDh6wsw4esLMOHrCzDh6wsu4esLLeHrCy7h6wsu4esLL+HrCy7h6wst4esLLeHrCy3h6wsu4esLLuHrCy7h6wsu4esLLeHrCy3h6wst4esLLeHrCy7h6wsu4esLLuHrCyzh6wsu4esLLeHrCy7h6wsu4esLLuHrCy7h6wsu4esLLeHrCy7h6wsu4esLLuHrCzHh6wsy4esLMuHrCzLh6wsz4esLNOHrCzLh6wsy4esLMuHrCzPh6wsy4esLMuHrCzDh6wsw4esLMeHrCzHh6wsx4esLMOHrCzDh6wsw4esLMeHrCzHh6wsv4esLMOHrCy/h6wst4esLLeHrCyvh6wsq4esLKuHrCyzh6wss4esLLOHrCy3h6wst4esLLOHrCyvh6wsr4esLKuHrCyrh6wsq4esLKuHrCyjh6wsp4esLKOHrCynh6wso4esLK+HrCyvh6wss4esLK+HrCyvh6wsr4esLK+HrCyvh6wsr4esLKeHrCyrh6wsp4esLKOHrCyjh6wsp4esLKOHrCynh6wso4esLKeHrCynh6wsp4esLKOHrCyjh6wsn4esLJ+HrCybh6wsn4esLJuHrCybh6wsl4esLJOHrCyXh6wsm4esLJuHrCybh6wsm4esLJuHrCybh6wso4esLKOHrCynh6wsp4esLKeHrCynh6wsp4esLKeHrCyjh6wso4esLKeHrCynh6wsp4esLKOHrCyjh6wso4esLKeHrCyjh6wsp4esLKeHrCyjh6wso4esLKeHrCynh6wsq4esLK+HrCyvh6wsr4esLK+HrCyvh6wsr4esLK+HrCyzh6wss4esLLOHrCyrh6wsp4esLKeHrCynh6wsp4esLKOHrCyjh6wso4esLJ+HrCyfh6wsn4esLJ+HrCyfh6wsn4esLJ+HrCyjh6wsn4esLJuHrCyXh6wsl4esLJOHrCyXh6wsl4esLJOHrCyTh6wsj4esLI+HrCyTh6wsk4esLJOHrCyTh6wsl4esLJuHrCyXh6wsl4esLJeHrCyfh6wsm4esLJuHrCyfh6wsn4esLJuHrCybh6wsm4esLJuHrCyfh6wsn4esLJ+HrCyfh6wsn4esLJ+HrCyfh6wso4esLJ+HrCyjh6wso4esLKeHrCyjh6wso4esLKeHrCy3h6wss4esLLuHrCy3h6wsv4esLL+HrCy7h6wsv4esLL+HrCzHh6wsy4esLMuHrCzLh6wsz4esLM+HrCzXh6ws04esLNOHrCzTh6ws04esLNuHrCzXh6ws14esLNeHrCzbh6ws24esLNuHrCzfh6ws34esLN+HrCzfh6ws44esLN+HrCzjh6ws34esLNuHrCzfh6ws24esLNuHrCzbh6ws24esLNuHrCzbh6ws14esLNeHrCzXh6ws04esLNeHrCzfh6ws24esLNuHrCzjh6ws54esLOeHrCzrh6ws64esLOuHrCzvh6ws64esLOeHrCznh6ws54esLOuHrCzjh6ws64esLOuHrCzvh6ws74esLOuHrCzvh6ws64esLOuHrCzvh6ws64esLO+HrCzvh6ws74esLOeHrCzjh6ws44esLOOHrCzjh6ws44esLOOHrCzjh6ws34esLN+HrCzfh6ws34esLN+HrCzfh6ws34esLN+HrCzfh6ws34esLN+HrCzbh6ws24esLNeHrCzTh6ws04esLNeHrCzXh6ws04esLNeHrCzbh6ws34esLNuHrCzXh6ws24esLN+HrCzfh6ws24esLN+HrCzfh6ws34esLN+HrCzfh6ws24esLN+HrCzfh6ws24esLNuHrCzXh6ws04esLNOHrCzTh6wsz4esLMuHrCzLh6wsy4esLMuHrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzPh6ws04esLNOHrCzPh6ws04esLNOHrCzTh6ws04esLNOHrCzPh6wsz4esLMuHrCzPh6wsy4esLM+HrCzLh6wsz4esLMuHrCzPh6wsy4esLM+HrCzPh6wsz4esLM+HrCzLh6wsy4esLMuHrCzLh6wsy4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLMuHrCzPh6ws04esLNOHrCzXh6ws14esLN+HrCzfh6ws34esLN+HrCzjh6ws34esLNeHrCzXh6ws24esLNeHrCzXh6ws14esLNeHrCzXh6ws14esLNeHrCzXh6ws14esLNeHrCzXh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6wsz4esLM+HrCzPh6wsz4esLNOHrCzPh6ws04esLNOHrCzTh6ws04esLNOHrCzXh6ws04esLNeHrCzXh6ws14esLNuHrCzfh6ws34esLN+HrCzfh6ws24esLNuHrCzfh6ws24esLNeHrCzXh6ws04esLNOHrCzXh6ws04esLNOHrCzXh6ws24esLNuHrCzbh6ws24esLNeHrCzTh6ws14esLNeHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzTh6ws04esLNOHrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLM+HrCzPh6wsz4esLMuHrCzLh6wsx4esLMeHrCzHh6wsx4esLMeHrCzDh6wsv4esLMOHrCzDh6wsw4esLL+HrCy/h6wsv4esLMOHrCzLh6wsy4esLL+HrCy/h6wsv4esLMOHrCy/h6wsv4esLMeHrCzHh6wsy4esLM+HrCzPh6wsy4esLMuHrCzLh6wsy4esLM+HrCzLh6wsy4esLM+HrCzPh6wsz4esLMuHrCzPh6wsz4esLM+HrCzPh6wsy4esLMuHrCzHh6wsz4esLMeHrCzHh6wsx4esLMeHrCzLh6wsx4esLL+HrCy7h6wsw4esLMeHrCzDh6wsx4esLMOHrCzHh6wsw4esLL+HrCy/h6wsr4esLK+HrCynh6wso4esLKeHrCybh6wso4esLKOHrCybh6wsl4esL","DeltaDateTime":"AAAAAMgGAAC4EQAAChQAAP4WAABIHAAAcSMAABosAABUNAAAMD4AALZJAAAHUQAAIF0AAGJmAAA8bwAAhXgAAH2AAABAiAAA3o8AANKXAADAnwAAZqgAAGGwAAA3twAALsMAAOnIAACSzAAA79EAAPDXAAAg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SCwCy1AsAwNkLAKTiCwCP6gsAY/MLAMb8CwDFBAwAlQwMAP4UDAD6HAwA5CQMAIcuDABNNgwAlT4MANpGDACxTwwAGFkMAKdjDACSawwAuXQMAJ18DAC3gAwA64gMAEqRDABumQwA26IMAF6vDAChtAwADsMMACnNDADw1QwAxt0MAG7kDADa5gwAGOoMAPLxDABL+wwA5gINABQMDQCHFA0A/hwNAE4nDQByMA0A6DINAC81DQAuPQ0AJUQNAPVGDQDSSQ0AYEwNAIZPDQBdUg0A2lQNAH5XDQD0XQ0AAGYNANptDQAwdw0A5H0NAE2ADQAHhQ0AaogNAAyRDQDsmA0AQqINAH6rDQA3tA0AXrwNAPLEDQCmzg0A4NYNALTeDQBj5w0AYu8NAGT3DQDG/w0ALAgOAN8QDgAQGQ4ACyEOACQpDgA6MQ4AUDkOAC5BDgA9SQ4ADE8OAGFXDgCuXA4A218OAHZiDgCAZw4AR3EOAGJ3DgDieQ4AGXwOAJl+DgC/gA4Am4sOAJaTDgDumQ4AaKIOAMumDgAJrw4A4bgOALvADgD2yQ4A0MwOAOjWDgDP3g4AEuUOAIztDgAQ9g4AhvgOAIgADwBqBA8ASgwPAHQODwAeFA8Aix0PANYfDwBFIg8AnCcPAL4pDwD/Kw8A8TQPAEA9DwBmPw8AQEcPALpKDwA6Ug8AwFQPANZWDwDlWQ8Aq1wPAHFfDwD0YQ8AN2cPAElpDwDWaw8AWnMPAPF1DwCteA8AenwPAFaGDwDGiQ8A6IsPANGVDwDxmA8AF5sPAL6hDwD8pA8AH6cPAMSqDwCHrQ8AALAPAH2yDwCMtA8ApLYPAAvADwCaxQ8A","CurrentTime":"2014-12-21 12:36:48.939","PrecisionDigits":2,"SpreadPipsCount":5,"IsDynamicSpread":false}
Hi,
I'm getting the following response using:
$json_object = json_decode($unparsed_json, true); array(1) { ["google.com"]=> array(2) { ["status"]=> string(16) "regthroughothers" ["classkey"]=> string(6) "domcno" } }How do I echo the attribute of the ['status']? I have tried using: echo $json_object->['status'];Thanks, MoFish I am making a simple login with jQuery ajax but I have a little problem. I get no response from my loginizer.php . My login page (index.php) contains the following code.
<form action="loginizer.php" onsubmit="return submitForm();" method="post" class="box"> <div id="error" ></div> <input id="matNo" name="matNo" class="input is-link is-rounded" type="text" placeholder="e.g. 2015/1/55852EE"> <input id="password" name="password" class="input is-link is-rounded" type="password" placeholder="********"> <button type="submit" id="submit" name="submit" class="button is-link is-small">Login</button></form>
My loginizer php contains the code:
<?php if(isset($_POST['submit'])){ require("db.php"); $table="Students"; $pUser=$_POST['matNo']; $pPass=$_POST['password']; $sql= $conn->prepare("SELECT * FROM $table WHERE Email=?"); $sql->bind_param("s",$pUser); $sql->execute(); $result = $sql->get_result(); $row = $result->fetch_assoc(); $user= $row['Email']; $pass = $row['Password']; $errMsg="Invalid Credentials"; $errMsg1="username doesn't exist"; $successMsg = "successLogin"; if($result->num_rows < 1) { echo json_encode($errMsg1); exit; } elseif($pUser == $user && $pPass !== $pass) { echo json_encode($errMsg); exit; } else{ echo json_encode($successMsg); exit; } } ?>
Ans lastly myJquery.js file which contains:
function submitForm() { var userid=$("#matNo").val(); var pass=$("#password").val(); if(userid!="" && pass!="") { $("#submit").html("Please Wait..."); $.ajax ({ type:'post', url:'loginizer.php', data:{ matNo:userid, password:pass }, dataType:'json', success:function(response) { if(response=="successLogin") { window.location.href="dash/home/"; } else { $("#error").html(response); //alert("Wrong Details"); } } }); } else { alert("All details are required"); } return false; }
The issue is that I get blank response . If I also change the url in the jQuery/Ajax code to index.php, it comes back with a response consisting of the html of the index.php. If I remove the dataType: 'json', it's still no response.
Thanks for your help in advance!!! Hi Guys, I have this SOAP message to be parsed using SimpleXML: <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:body> <isokresponse xmlns="http://tempuri.org/"> <isokresult>1</isokresult> </isokresponse> </soap:body> </soap:envelope> Then I load the XML: $xml = simplexml_load_string($result); I assume I need to register namespace e.g. $xml->registerXPathNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/"); But what's next? How do I get the value of the element isokresult? Thank you so much Ok this is driving me NUTS! After using SoapClient() this is the response i get back... Code: [Select] <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <ns1:GetRegistrationURLResponse xmlns:ns1="http://impl.service.tempuri.com"> <ns1:out> <errorCode xmlns="http://model.tempuri.com">0</errorCode> <errorMessage xmlns="http://model.tempuri.com" xsi:nil="true" /> <registrationURL xmlns="http://model.tempuri.com"> https://www.tempuri.com/external/authenticate?org=orgname&token=uXiqcPV4%2FuEifbaR80PVBTxH4Oqd3tF%2BiEYaz%2F1OHJG7b5oxN7Bi8AIulmtbwATnjri2P1vCNy%2Fu77OzQEV2lQ%3D%3D </registrationURL> </ns1:out> </ns1:GetRegistrationURLResponse> </soap:Body> </soap:Envelope> So all i really need to pull out of there is the <registrationURL> I assign the response to a variable Code: [Select] <?php $xml_response = $client->__getLastResponse(); ?> use SimpleXML Code: [Select] <?php $xml = simplexml_load_string($xml_response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/"); ?> Using the code Code: [Select] print_r($xml); displays this --> SimpleXMLElement Object ( [Body] => SimpleXMLElement Object ( ) ) I have tried many ways, what i have now is this: Code: [Select] <?php $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); $xml->registerXPathNamespace('ns1', 'http://impl.service.tempuri.com'); #$xml->registerXPathNamespace('registrationURL', 'http://model.tempuri.com'); foreach ($xml->xpath('//ns1:GetRegistrationURLResponse/ns1:out') as $item) { echo $item->asXML(); } ?> but the result of that is 0https://www.tempuri.com/external/authenticate?org=nyit&token=uXiqcPV4%2FuEifbaR80PVBTxH4Oqd3tF%2BiEYaz%2F1OHJG7b5oxN7Bi8AIulmtbwATn3QmJanSYWqzS%2FgZM4eR%2Fcg%3D%3D parsed by browser... actual source XML is Code: [Select] <ns1:out><errorCode xmlns="http://model.tempuri.com">0</errorCode><errorMessage xmlns="http://model.tempuri.com" xsi:nil="true"/><registrationURL xmlns="http://model.tempuri.com">https://www.tempuri.com/external/authenticate?org=orgname&token=uXiqcPV4%2FuEifbaR80PVBTxH4Oqd3tF%2BiEYaz%2F1OHJG7b5oxN7Bi8AIulmtbwATn3QmJanSYWqzS%2FgZM4eR%2Fcg%3D%3D</registrationURL></ns1:out> but i cannot for the life of me just pull out registrationURL so that i can somehow turn it into a link. Any ideas? |