PHP - Web Service Xml Unserialize Results
Hi,
I'm new to PHP and wondered if anyone could help... I am consuming an asmx webservice using PHP code. (Later to make a widget for wordpress). I can receive all the data, but it is in one very big xml file. I want to be able to convert this data, so I can make it more readable. Could really do with help as I don't have a clue how to convert it. ANy ideas? Similar TutorialsOkay, On my original problem, I have been able to authenticate with the web service login service, and extract a cookie as follows from the web-service: $s_Cookie = $agLoginService->agGetCookie(); $s_Cookie = AGSESSION=oxhbjcKtPw5sOymAD8m8KcKR6JL4i+TIE5mZxwOrXLwCRr8iTOvPxA==; Now, I create data access soapclient: $agDataService = new SoapClient($s_DataURL, $a_SoapOptions); //yes I know I should build my own class wrapper around soapClient, but I am trying to make sure I know what to build before I do next in the process I need to set the cookie for the data access service. I tried using: <b>$agDataService->__setCookie('cookie', $s_Cookie);</b> but I don't think it's right because when I call any of the service's functions, I get no data back. This is what their engineer had to say ( he is no help in php at all) This is a question referring the http headers. He needs to set the cookies as given in the examples on the wiki page. The cookie is specified in a response http header as: Set-Cookie. So the http headers he got back are correct. The cookie he has to set is AGSESSION=oxhbjcKtPw5sOymAD8m8KcKR6JL4i+TIE5mZxwOrXLwCRr8iTOvPxA==; There should be an api for setting the cookie if not there is one for setting the http header. Set the http header name for the request (cookie - notice that is different than what you get back from an http response - read the rfc spec for http for all of the details) then set the value. The semi colon at the end is the delimiter for http headers (in the rfc). That is all he needs to do if he gets back some login error that means the cookies did not get set correctly. Any ideas or help will be great. Thank you. guys this is my code <?php include("header.php"); include("conn.php"); ?> <html> <head> </head> <body> <table border="1" cellpadding="0" cellspacing="0" align="center"> <tr> <td>Please Enter the Amount</td> <td valign="top" align="left" width="200"> <form action="next.php" method="post"> <input name="amount" value="1" size="7"> </td> <tr> <td>From:</td> <td valign="top" align="left" width="200"> <?php $real= array ( 'USD'=>1, 'PAK'=>1.6323, 'GBP'=>1.02544 ); $abc= mysql_real_escape_string( serialize($real) ); //$ddsr=unserialize($abc); //$abc= implode(",",$real); //echo $abc; $from= array('Dollars','Rupees','Pounds'); $length = count($from); //$dbs=implode(",",$from); $dql = "INSERT INTO countrytype (`ID`,`fromcountry`,`tocountry`) VALUES ('','".$abc."','".$abc."')"; mysql_query($dql) or die(mysql_error()); $to= array('Dollars','Rupees','Pounds'); $to=str_replace("","",$to); ?> <input type="hidden" name="h1" value="<?php echo $length;?>"> <select> <?PHP $dgd= "SELECT * FROM countrytype GROUP BY ID"; $aws= mysql_query($dgd) or die(mysql_error()); while($row=mysql_fetch_array($aws)) { $des=stripslashes($row['fromcountry']); $dsw=unserialize($des); //$des=explode("",$row['fromcountry']); //var_dump($dsw); //echo "<td>".$row['ID']."<td>"; //echo "<td>".$dsw."<td>"; $k=1; foreach($dsw as $key=>$value) { echo "<option name='ad[]' value='$value'>$value</option>"; //print_r(array_keys($des)); $k++; } } //$sss=explode("",$row['fromcountry']); //echo $sss; ?> </select> <select> <?php $i=0; $k=1; foreach($from as $abd => $value) { echo "<option name='ar[]' value='$value' >$value</option>"; $k++; } ?></td></tr></select> <td>To: </td><td><select> <?php foreach($to as $abd => $value) { $i++; echo "<option id='i' >$value</option>"; } ?> </select> <input type="submit" name="sub" value="Convert!"/> </form> </td> </tr> </tr> </table> </body> </html> serilization works but when i fetch it from database and unserialize it nothing works i tried to serialize an array in php but im not sure if i had the right syntax $field[0] = "Student Name"; $field[1] = "fail"; $field_ser = serialize($field); $field_unser = unserialize($field_ser); i think i didnt do it right I took an object, and saved it into a database serialized. Code: [Select] $object_here = serialize($theobject); Then later on, I go and I get that data from a database, and try to unserialize it.. Code: [Select] $objecthere = unserialize($row->theobject) And it throws the following error...any advice? Quote Warning: unserialize() [function.unserialize]: Node no longer exists in /path/to/file on line 20 Hey I got this script which is trying to unserialize but i get this error and have no idea what it means so i equally have no idea how to fix the problem. This is what it says: Quote Notice: unserialize() Error at offset 0 of 4 bytes This is the line which causes the error: Code: [Select] <?php $contents = unserialize(file_get_contents($this->msgsFile)); ?> Does any one know what the error means? And what i need to look for to fix it. Need a bit of help with some php and a few kind members helped me in the past. My code is: $query = "SELECT names FROM table WHERE type='$type'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { foreach(unserialize($row['names']) as $key => $value){ echo $value . '<br />'; } } Basically, a field on my table is called names. The information in this field is serialized (so many names are together in a single field, for a single row). I want to be able to search the whole table (where type='$type' - so many rows) for all names and then show unique names only. My code above unserializes the names from each field and then lists them, but doesn't deal with any duplicates (which I need removing). I have looked at functions like "unique_array()", and have tried using it in different places but it isn't doing the job. Any help appreciated. I am trying to unserialize this string: a:3:{s:3:\"zip\";s:5:\"55068\";s:4:\"city\";s:9:\"Rosemount\";s:5:\"state\";s:2:\"MN\";} but I unserialize is returning false. Why is it doing that? $info = unserialize($_COOKIE['zipcode']); var_dump($info); Hi everyone, Im trying to serialize the values of checked checkboxes, save them to a database, then on another page retrieve the value from the database, unserialize it, and then write each checkbox value to the database individually. Using the following test code I'm able to serialize the checkbox values, and then unserialize them and echo them out fine, however im unsure how to separate them and save them individually into the database. $string = implode($_POST['checkbox']); $test = serialize($string); $test2 = unserialize($test); echo $test2; <?php $i = 0; ?> <?php while ($row = mysql_fetch_assoc($query)) { ?> <tr> <td><input type="checkbox" name="<?php echo "checkbox[$i]"; ?>" value="<?php echo $row['test']; ?>" /></td> </tr> <?php $i++; } ?> Any ideas? Thanks my user pm table has a touserarray field which is a serialized array that looks like this: a:1:{s:2:"cc";a:1:{i:15773;s:14:"testusername";}} i know I can unserialize it with the unserialize() function. But I need to extract the value corresponding to 'i' field and the 's' field that has the username. So from the above array, i need to retrieve the value '15773' and 'testusername'. Can someone tell me how? Is this a mistake in the documentation? I am running PHP7.4 and get warning: unserialize() expects parameter 2 to be array, bool given. QuoteEither an array of class names which should be accepted, false to accept no classes, or true to accept all classes. If this option is defined and unserialize() encounters an object of a class that isn't to be accepted, then the object will be instantiated as __PHP_Incomplete_Class instead. Omitting this option is the same as defining it as true: PHP will attempt to instantiate objects of any class.
I have an array from the database like so Array (2) ( | ['0'] => Array (4) | ( | | ['f_fid'] = String(1) "1" | | ['0'] = String(1) "1" | | ['f_names'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | | ['1'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | ) | ['1'] => Array (4) | ( | | ['f_fid'] = String(1) "2" | | ['0'] = String(1) "2" | | ['f_names'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | | ['1'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | ) ) So i use a foreach loop to turn the serialized value into an array foreach($fields as $key => $val) { $fields[$key]['f_names'] = unserialize($val['f_names']); } But for some reason the last f_names is false Array (2) ( | ['0'] => Array (4) | ( | | ['f_fid'] = String(1) "1" | | ['0'] = String(1) "1" | | ['f_names'] => Array (4) | | ( | | | ['0'] = String(18) "register_user_name" | | | ['1'] = String(5) "r_u_n" | | | ['2'] = String(10) "user_alias" | | | ['3'] = String(12) "nickusername" | | ) | | ['1'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | ) | ['1'] => Array (4) | ( | | ['f_fid'] = String(1) "2" | | ['0'] = String(1) "2" | | ['f_names'] = Boolean(0) FALSE | | ['1'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | ) ) Anyone have any idea why? Thanks Debian 5 PHP 5.2.6-1 This script works: <? $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?> This script doesn't work: <? $vars=unserialize(file_get_contents("file.txt")); $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?> I get error: Quote Warning: shell_exec(): Unable to execute 'ls -lart' or Warning: system(): Unable to fork [ls -lart] If file.txt has size 500k, the script works without errors. But my file file.txt has size 30M. Help. the code is simple but the output is wrong. Code: [Select] $str = <<<EOF a:2:{s:7:"visible";a:7:{i:0;s:5:"email";i:1;s:5:"print";i:2;s:8:"facebook";i:3;s:4:"digg";i:4;s:11:"stumbleupon";i:5;s:7:"twitter";i:6;s:6:"reddit";}s:6:"hidden";a:0:{}} EOF; echo "<textarea rows='10' cols='90'>";print_r(unserialize($str));echo "</textarea>"; the ouput is Code: [Select] Array ( [visible] => Array ( [0] => email [1] => print [2] => facebook [3] => digg [4] => stumbleupon [5] => twitter [6] => reddit ) [hidden] => Array ( ) ) This is wrong I need something like this: Code: [Select] array ( 'visible' => array ( 0 => 'email', 1 => 'print', 2 => 'facebook', 3 => 'digg', 4 => 'stumbleupon', 5 => 'twitter', 6 => 'reddit', ), 'hidden' => array ( ), ) What am I doing wrong? How do I fix it? Hello, I have a call tu function unserialize() in a script that receives a string and has to return an array. In my localhost it works properly but in the server it returns a 1 dimension array with empty value. I'm testing with the string a:1:{s:1:"0";s:8:"value_eq";} The php.ini configuration for magic_quotes is (in both, server and localhost): magic_quotes_gpc Off magic_quotes_runtime Off Other configurations is difficult to compare, as php info is long and very different in local and server. Any ideas where the problem might be? Thank you I'm getting the following result from a web service call. I'd like to pass it to another page, possibly using sessions, and then access specific values on that page, such as FirstName.
stdClass Object ( [GetProspectAsJSONResult] => [ { "ProspectId": xxxxxx, "Keycode": "Test", "FirstName": "Test", "LastName": "Test", "Company": "Test","Email": null } ] )
I'm not sure what the best way to do this is.
Thanks!
Hi Guys/Gals, I am new to PHP and when I say new, I mean I know a variable is $variable name... that is about it. I am a .Net developer, always was, now I have to learn some php. I have a .Net payment gateway service that I would like to reference from a php site. I was hoping anyone could point me in the right direction on how to go about adding a .Net Service and pointing to it in PHP. Please note this is a WPF service, thus it is a .svc page not a .asmx and it is hosted and running on iis on a server. Please some guidance? Any help would be appreciated. Hi, guys. I just developed and published first version of 12framework for iOS which can call also PHP web services.
It is web service client which generates dynamic forms from web service results, and enables insert, update and delete of records. You can simply change result field type to text, memo, date, bool.
I also made some simple PHP web service to test functionallity of application, so I will really appreciate your feedback. iOS is locked platform, so 12framework provides possibility, to make some useful data forms that works as native application. Link: https://itunes.apple...88083?ls=1&mt=8
I have service /usr/lib/systemd/system/socketserver.service defined as follows: [Unit] Description=Socket Server After=syslog.target [Service] ExecStart=/usr/bin/php /var/www/socket/server.php Restart=on-abort Restart=on-failure RestartSec=10s [Install] WantedBy=multi-user.target When hitting the following lines: $cmd="tshark -f 'port 1337' -i eno16780032 -a duration:4 -w /var/www/socket/tmp/test.pcap"; $status = exec($cmd, $output); syslog(LOG_INFO, 'results: '.json_encode($output).' status: '.($status?'success':'false')); I get the following: Jun 04 18:58:56 tapmeister.com php[43111]: Running as user "root" and group "root". This could be dangerous. Jun 04 18:58:56 tapmeister.com php[43111]: Capturing on 'eno16780032' Jun 04 18:58:56 tapmeister.com kernel: device eno16780032 entered promiscuous mode Jun 04 18:59:00 tapmeister.com kernel: device eno16780032 left promiscuous mode Jun 04 18:59:00 tapmeister.com php[43111]: 0 packets captured Jun 04 18:59:00 tapmeister.com Server[43111]: results: [] status: false Sure enough, exec('whoami') confirms I am running as root. Probably shouldn't be. How would you recommend configuring? PS. the three lines shown regarding tshark are executed via an asynchronous request and are not in the main loop. Hi! I need to retrieve data from a WCF Web Service and don't seem to be connecting when the "new SoapClient" is called. I am using php version 5.2. The service requires 2 Parmameters, an account ID and a comma separated email list. Can someone please tell me what I am doing wrong? Thanks! Code: [Select] <?php header('Content-Type: text/xml'); $client = new SoapClient('http://www.zbestlistings.com/WCF/Primedia.svc?wsdl'); $response = $client->GetPropertyXML(array( "AccountID" => "12807175152", "eMailList" => "Sheryl@Rentingslc.com, Tenants@Rpmwestvalley.com, Tom@Rpmsouthernutah.com" )); echo $response; ?> |