PHP - Php Performing On Xml Response
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}; ? 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 wish to find a way to test if multiple sites are up or not. I have been using get_headers but it seems that this does not do what I thought I would. I wish to know if the sites are down or not. Is there another function that can test what state the site is in. i.e. server not found, server issues prevented the page from showing... Using get_headers will still show the site is live even if the server is not found, due to server problems, if any. Hello there, I have a problem with this project I'm working on, everything is working fine except for one last thing. it goes as you go to the website, search for a city, choose a hotel from a list in that city, then book a room in that hotel, go to confirmation page then to paypal. everything is fine except after the booking when you go to the confirmation page, it shows correctly the number of nights you booked and everything, all except the rooms, it shows 0 rooms selected, and it doesn't give any price at all. here is the code Code: [Select] <?php include("db.class.php"); class hotelManager { public function getHotel($where) { $where = isset($_POST['where']) ? $_POST['where'] : ""; $dbObj = new DB(); $where = $_POST['where']; $sql = "select * from hotels where city_id IN (select id from cities where name = '$where') or country_id IN (select id from countries where name = '$where')"; $result = mysql_query($sql); $arr = array(); echo "<table>"; while($row = mysql_fetch_array($result) or die(mysql_error())) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid'"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\"> <a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink\">".$row['name']."</a> </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> </table>"; echo "</td>"; echo "</tr>"; } echo "</table>"; //return $arr; // array of arrays } /*************************** GET ONE HOTEL *****************************/ public function getHotelbyID($hotelID) { $dbObj = new DB(); $result = mysql_query("select * from hotels where id = '$hotelID'"); return $result; } public function HotelDatatabel($result) { $row = @mysql_fetch_array($result); echo "<table width=98%>"; echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\" class=\"searchtitle\"> ".$row['name']." </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> <tr> <td> ".$row['details']." </td> </tr> <tr> <td> <a href=\"http://".$row['website']."\" class=\"link\">".$row['website']."</a> </td> </tr> </table>"; echo "</td>"; echo "</tr>"; echo "</table>"; } /************************************ GET ROOMS **************************************/ public function getHotelRooms($hotelID) { $result = mysql_query("select * from rooms where hotel_id = '$hotelID'"); echo "<form name='bookingform' id='bookingform' method='post' action='book.php'>"; echo "<input name=\"roomid\" id=\"roomid\" type=\"hidden\" />"; echo "<input name=\"roomnum\" id=\"roomnum\" type=\"hidden\" />"; echo "<input name=\"hotelid\" id=\"hotelid\" type=\"hidden\" value=\"$hotelID\"/>"; echo "<table width=80% >"; echo"<tr>"; echo "<td>Check-in date</td>"; echo "<td>"; echo "<input type=\"text\" name=\"datein\" class=\"date_input\" />"; echo "</td>"; echo "<td>Check-out date</td>"; echo "<td>"; echo "<input type=\"text\" name=\"dateout\" class=\"date_input\" />"; echo "</td>"; echo"</tr>"; echo "<table>"; echo "<table class=\"rooms\" width=100% cellspacing=\"1\" >"; echo "<tr> <th class=\"rooms\">Room Type</th> <th class=\"rooms\">Rate for night</th> <th class=\"rooms\">MAX</th> <th class=\"rooms\">Nr.rooms</th> <th class=\"rooms\">Book</th> </tr>"; while($row = @mysql_fetch_array($result)) { echo "<tr>"; echo "<td class=\"text\" align=center>".$row['room_type']."</td>"; echo "<td class=\"text\" align=center>".$row['price_per_day']."</td>"; echo "<td class=\"text\" align=center>".$row['people']." People</td>"; echo "<td class=\"text\" align=center>"; ?> <select name="nrooms" id="nrooms" onchange=" //alert('<?php echo $row['id'] ; ?>'); //alert(this.value); var exist = 0; if(roomids.length > 0) { for(var hh = 0;hh < roomids.length; hh++) { if(roomids[hh] == <?php echo $row['id'] ; ?>) { exist = 1; //alert(hh); roomnumar[hh] = this.value; } } if(exist == 0) { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } } else { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } document.bookingform.roomid.value = roomids; document.bookingform.roomnum.value = roomnumar; "> <option value=0> 0 </option> <?php for($i = 0; $i < $row['available_rooms']; $i++) { $nr = $i+1; $pr=$nr * $row['price_per_day']; echo "<option value=$nr>$nr ($pr\$)</option>"; } echo "</select> </td>"; echo "<td align=center> </td>"; echo "</tr>"; echo "<tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr>"; } echo "<tr class=\"rooms\"> <td colspan=\"4\"> </td> <td align=center><input type=\"submit\" value=\"book\" id=\"bookroom\" name=\"bookroom\"/></td> </tr>"; echo "</table>"; echo "</form>"; print_r($_SESSION['order']); $_SESSION['order']=0; unset($_SESSION['order']); } } ?> BookinManager.php Code: [Select] <?php include("hotelsManager.php"); ?> <?php include("config.php"); ?> <?php include("textManager.php"); ?> <?php function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $datein = $_POST['datein']; $dateout = $_POST['dateout']; $roomid = $_POST['roomid']; $pr = $_POST['pr']; $_SESSION['hotelID'] = isset($_POST['hotelid']) ? $_POST['hotelid'] : $_SESSION['hotelID']; $_SESSION['datein'] = isset($_POST['datein']) ? $_POST['datein'] : $_SESSION['datein']; $_SESSION['dateout'] = isset($_POST['dateout']) ? $_POST['dateout'] : $_SESSION['dateout']; $_SESSION['roomid'] = isset($_POST['roomid']) ? $_POST['roomid'] : $_SESSION['roomid']; $roomsarray = explode(",",$_POST['roomid']); $_SESSION['roomsarray'] = isset($_POST['roomid']) ? explode(",",$_POST['roomid']) : $_SESSION['roomsarray']; $roonsNo = $_POST['nrooms']; $_SESSION['nrooms'] = isset($_POST['roomnum']) ? explode(",",$_POST['roomnum']) : $_SESSION['nrooms']; /********************** hotels ************************/ /******************************************************/ echo "<table width=95% border=0 align=\"center\" cellpadding=\"0\" cellspacing=\"0\"> <tr><td valign=\"top\">"; echo "<table>"; echo "<tr>"; echo "<td valign=top>"; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='".$_SESSION['hotelID']."' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td>"; $result=$hotelObj->getHotelbyID($_SESSION['hotelID']); $row = mysql_fetch_array($result); echo "<table>"; echo "<tr><td valign=top><strong class=subtitle3>".$row['name']."</strong></td></tr>"; echo "<tr><td class=text valign=top>".$row['location']."</td></tr>"; echo "<tr><td class=text valign=top>check-in Date: ".$_SESSION['datein']."</td></tr>"; echo "<tr><td class=text valign=top>check-out Date: ".$_SESSION['dateout']."</td></tr>"; echo "<tr><td class=text valign=top>"; $newdate = $_SESSION['dateout'] - $_SESSION['datein']; $totalprice = array_sum($_SESSION['totalprice']) echo "</td></tr>"; echo "<tr><td class=text valign=top>Total Price: ".$totalprice."</td></tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td></tr></table>"; } function echoForm2() { ?> <form id="userDetails" name="userDetails" action="" method="post"> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top" class="subtitle3"><strong>Your Name</strong><br /> <input type="text" name="name" size="50" /></td> </tr> <tr> <td valign="top" class="subtitle3"><strong>Email address</strong><br /> <input type="text" name="email" size="50" /> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td valign="top" class="subtitle3"> <?php $roomsarray = explode(",",$_POST['roomid']); $roonsNo = explode(",",$_POST['roomnum']); for($i = 0;$i<count($roomsarray);$i++) { if($roonsNo[$i] > 1) { for($j = 0;$j<$roonsNo[$i];$j++) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']." #".($j+1)."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name </strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } else { if($roonsNo[$i] != 0) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name</strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } } ?> <hr> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit" id="submit" value="Make the reservation" /> </td> </tr> </table> </form> <?php } ?> Code: [Select] <?php include("includes/bookinManager.php"); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <th align="left" valign="top" class="formtable"> Booking Data </th> </tr> <tr> <td valign="top"> </td> </tr> <tr> <td valign="top"> <?php echoPostedData(); ?> </td> </tr> <tr> <td valign="top"> </td> </tr> </table> </td> </tr> <tr> <td valign="top"><img src="images/spacer.gif" width="28" height="10" /></td> </tr> <tr> <td valign="top"> <?php if(isset($_POST['bookroom'])) {?> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <th align="left" valign="top" class="formtable"> Your Details </th> </tr> <tr> <td valign="top" > <form action="book.php" method="post" id="payPalForm"> <table width="60%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <td>First name :</td> <td><input type="text" name="first_name" /></td> </tr> <tr> <td>Last name :</td> <td><input type="text" name="last_name" /></td> </tr> <tr> <td>Email address :</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Full guest name :</td> <td><input type="text" name="full" /></td> </tr> <tr> <td>Address :</td> <td><INPUT type="text" NAME="address1" VALUE=""/></td> </tr> <tr> <td>Special Requests :</td> <td><input type="text" name="special" /></td> </tr> </table> </td> </tr> <tr> <td valign="top"> <?php //echoForm2(); ?> <input type="hidden" name="item_number" value="<?php echo $row['id']; ?>"> <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="tarek_1305896294_biz@gotharious.com"> <input type="hidden" name="item_name" value="Standard Room: Dar El Masyaf Hotel : 2 nights : 9th, july, 2011"> <input type="hidden" name="currency_code" value="USD"> <INPUT TYPE="hidden" NAME="first_name" VALUE="Tarek"> <INPUT TYPE="hidden" NAME="last_name" VALUE="Sabrouty"> <INPUT TYPE="hidden" NAME="address1" VALUE="9th Popastes St."> <INPUT TYPE="hidden" NAME="address2" VALUE="Cleopatra Hamamat"> <INPUT TYPE="hidden" NAME="city" VALUE="Alexandria"> <INPUT TYPE="hidden" NAME="Country" VALUE="Egypt"> <INPUT TYPE="hidden" NAME="lc" VALUE="US"> <INPUT TYPE="hidden" NAME="email" VALUE="tarek@gotharious.com"> <INPUT TYPE="hidden" NAME="night_phone_a" VALUE="+20166005733"> <INPUT TYPE="hidden" NAME="amount" VALUE="100.00"> <?php $roomsarray = explode(",",$_POST['roomid']); $roonsNo = explode(",",$_POST['roomnum']); for($i = 0;$i<count($roomsarray);$i++) { if($roonsNo[$i] > 1) { for($j = 0;$j<$roonsNo[$i];$j++) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']." #".($j+1)."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name </strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } else { if($roonsNo[$i] != 0) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name</strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } } ?> <input type="submit" name="Submit" value="Submit"> </form> <tr> <td valign="top"> </td> </tr> </table> <?php } ?> 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; } } 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? */ ?> 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!"); } } } ?> 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 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? 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 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. 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+HrCzPh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AZw4AR3EOAGJ3DgDieQ4AGXwOAJl+DgC/gA4Am4sOAJaTDgDumQ4AaKIOAMumDgAJrw4A4bgOALvADgD2yQ4A0MwOAOjWDgDP3g4AEuUOAIztDgAQ9g4AhvgOAIgADwBqBA8ASgwPAHQODwAeFA8Aix0PANYfDwBFIg8AnCcPAL4pDwD/Kw8A8TQPAEA9DwBmPw8AQEcPALpKDwA6Ug8AwFQPANZWDwDlWQ8Aq1wPAHFfDwD0YQ8AN2cPAElpDwDWaw8AWnMPAPF1DwCteA8AenwPAFaGDwDGiQ8A6IsPANGVDwDxmA8AF5sPAL6hDwD8pA8AH6cPAMSqDwCHrQ8AALAPAH2yDwCMtA8ApLYPAAvADwCaxQ8A","CurrentTime":"2014-12-21 12:36:48.939","PrecisionDigits":2,"SpreadPipsCount":5,"IsDynamicSpread":false}
Could i use curl to check api response time and if so how? 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. 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? 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 I have this php file that processes Form field entries. Apparently I need to modify it, I'm told, to "validate the input and then send some response back": <?php if($_POST){ $to = 'chrisj...@.....com'; $subject = 'Thank you for your info'; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $message1 = $_POST['message']; $headers = $name; $headers = 'from: info@.....com'; $message1 .= "\r\n\r\nName: ".$_POST['name']." \r\n Email: ".$_POST['email']." "; $message = "Hello {$_POST['name']}, ~ Thank you for your input\r\n\r\n"; mail( $to, $subject, $message1, $headers ); mail( $email, $subject, $message, $headers ); header('Location: https://....'); exit; } ?> The corresponding js looks like this: $.ajax({ url: 'https://...../submit.php', method: 'post', data: { name: $('#name').val(), email: $('#email').val() }, success: function (response) { console.log(response); if (response.success) { alert('Success'); } else { alert('Error'); } } }); I look forward to any guidance with adding "validate the input and then send some response back".
The array. Output of the variable $v Code: [Select] xmlrpcval Object ( [me] => Array ( [struct] => Array ( [sec] => xmlrpcval Object ( [me] => Array ( [string] => 349955dd5d3156af95cb4e75a13cffaa ) [mytype] => 1 ) ) ) examples of what I have tried echo $v->string; How could I get the value of [string]. I know that its an object but cannot find how to get the value. |