PHP - Call Soap Method Via Curl In Php,call Require Client Authentication
OVERVIEW:
The code is about making call to the escreen web service using SOAP and Curl with client authentication required. Currently I am not getting any result only HTTP 403 and 500 errors. The call requires client authenticate cert to be on the callng site. CODE: $content = "<TicketRequest> <Version>1.0</Version> <Mode>Test</Mode> <CommitAction></CommitAction> <PartnerInfo> <UserName>xxxxxxxxxx</UserName> <Password>xxxxxxxxxxx</Password> </ PartnerInfo> <RequestorOrderID></RequestorOrderID> <CustomerIdentification> <IPAddress></IPAddress> <ClientAccount>xxxxxxxxxx</ClientAccount> <ClientSubAccount>xxxxxxxxxx</ClientSubAccount> <InternalAccount></InternalAccount> <ElectronicClientID></ElectronicClientID> </CustomerIdentification> <TicketAction> <Type></Type> <Params> <Param> <ID>4646</ID> <Value></Value> </Param> </Params> </TicketAction> </TicketRequest>"; $wsdl = "https://services.escreen.com/SingleSignOnStage/SingleSignOn.asmx"; $headers = array( "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", // "SOAPAction: \"\"", "Content-length: ".strlen($content), ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $wsdl); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_VERBOSE, '1'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //curl_setopt($ch, CURLOPT_HTTPHEADER, array('SOAPAction: ""')); curl_setopt($ch, CURLOPT_CAPATH, '/home/pps/'); curl_setopt($ch, CURLOPT_CAINFO, '/home/pps/authority.pem'); curl_setopt($ch, CURLOPT_SSLCERT, 'PROTPLUSSOL_SSO.pem'); curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'xxxxxxxxxxxx'); $output = curl_exec($ch); // Check if any error occured if(curl_errno($ch)) { echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch); } print_r($output); QUESTIONS: 1. I need to call the RequestTicket method and pass the XML string to it. I don't know how to do it here(pass the method name to call). 2. For client authentication they gave us three certs, one root cert, one intermediate cert and a client authentication cert PROTPLUSSOL_SSOpem(it was a .pfx file). Since we are on linux we converted them to pem . In curl calls I could not find way to how to include both the root cert and the intermediate cert ,so I combined them by making a new pem file and copying the intermediate cert and them the root cert and naming it authority.pem . I am not sure whether it works or not and would like your opinion. 3. For the current code Iam getting the error Error no : 77 Curl error: error setting certificate verify locations: CAfile: /home/pps/authority.pem CApath: /home/pps/ If I disable the curl error message,I am getting blank page with page title 403 - Forbidden. Access is denied. If I comment out the CURLOPT_CAPATH and CURLOPT_CAINFO lines it gives http 500 error page with the message as content and the following at the top. > HTTP/1.1 500 Internal Server Error. Cache-Control: private Content-Type: text/html Server: Microsoft-IIS/7.5 X-AspNet-Version: 1.1.4322 X-Powered-By: ASP.NET Date: Thu, 02 Sep 2010 14:46:38 GMT Content-Length: 1208 If I comment out as above and also CURLOPT_SSLCERT and CURLOPT_SSLCERTPASSWD it gives 403 error with the message as content. So I would request you to help me out by pointing out whats wrong with the current code. Thank you. Similar TutorialsHi all, I'm a newbie in PHP trying to move away from the .net platform. I seem to have run into my first challenge passing a complex type back to my web service. The web service is a live test site to test against. I've tested the service on .net and it works fine...but I think I'm missing something as I try porting over to PHP? I've written some short code to keep it simple: <?php $SearchCriteria = array("ObjectType"=>1); $parameters['user'] = "johndoe1"; $parameters['password'] = "snowball"; $parameters['SearchCriteria'] = $SearchCriteria ; $client = new SoapClient("https://servicestest.mcquaig.com/mws.asmx?WSDL"); $result = $client->__soapCall('Find', $parameters); ?> ....against this portion of XML: <s:element name="Find"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="user" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="criteria" type="tns:SearchCriteria"/> </s:sequence> </s:complexType> </s:element> <s:complexType name="SearchCriteria"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="AccountName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="ApplySharing" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="CGType" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="ClientRefID" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="Composites" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="ConfNo" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Email" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="Expired" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSA" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSZ" type="s:dateTime"/> <s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="FormLangID" type="s:unsignedLong"/> <s:element minOccurs="1" maxOccurs="1" name="FunctionalArea" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Gender" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Industry" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="JobTitle" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="LastUsedTSA" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="LastUsedTSZ" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="NoRelated" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="ObjectType" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="OrgID" type="s:unsignedLong"/> <s:element minOccurs="1" maxOccurs="1" name="Position" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="ProfileType" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Recursive" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="Status" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Type" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="UnitsRemain" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="UnitsRemainGT" type="s:boolean"/> </s:sequence> </s:complexType> Nothing I seem to do works. I end up with the same error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Value does not fall within the expected range. Using NuSoap as: <?php require_once('lib/nusoap.php'); $SearchCriteria = array("ObjectType"=>1); $wsdlURL = "https://servicestest.mcquaig.com/mws.asmx?WSDL"; $soap = new nusoap_client($wsdlURL); $parameters['user'] = "johndoe1"; $parameters['password'] = "snowball"; $parameters['criteria'] = $SearchCriteria ; $result = $soap->call("Find", $parameters); if($error = $soap->getError()){ die($error);} ?> I get this error: soap:Client: Server did not recognize the value of HTTP Header SOAPAction: . I'm stumped and sure it's something small, but I just don't see what I'm missing?? Any suggestions are greatly appreciated!! Gary how to make 2FA Authentication by sms, call voice or email, i want to to make a step 2 for security in my application si If a login to myaccount is attempted i want to initiate 2fa with choice of SMS , email or call with PIN then to validate it are there any PHP frameworks or services Open Source or paid that could deliver this functionality for me? i found Nexmo sms but it is for sms only and twilio authy.. does any one have any reccomndation? I'm trying to use a simple wsdl file and make a soap call but for the life of me I can't get it to work. Here's the wsdl file: <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="urn:gnHPD_Staging_Table_Submit_Generic" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:s="urn:gnHPD_Staging_Table_Submit_Generic" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdl:types> <xsd:schema elementFormDefault="qualified" targetNamespace="urn:gnHPD_Staging_Table_Submit_Generic"> <xsd:element name="Submit" type="s:InputMapping"/> <xsd:complexType name="InputMapping"> <xsd:sequence> <xsd:element name="Assigned_To_Group" type="xsd:string"/> <xsd:element name="AutoPush" type="s:AutoPushType"/> <xsd:element name="Case_Type" type="s:Case_TypeType"/> <xsd:element name="Category" type="xsd:string"/> <xsd:element name="Description" type="xsd:string"/> <xsd:element name="Details" type="xsd:string"/> <xsd:element name="Entry_Number" type="xsd:string"/> <xsd:element name="Integration_Application" type="xsd:string"/> <xsd:element name="Item" type="xsd:string"/> <xsd:element name="Priority" type="s:PriorityType"/> <xsd:element name="Source" type="s:SourceType"/> <xsd:element name="Submitter_UNIX" type="xsd:string"/> <xsd:element name="Summary" type="xsd:string"/> <xsd:element name="Type" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="AutoPushType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Auto Push"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="Case_TypeType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Incident"/> <xsd:enumeration value="Question"/> <xsd:enumeration value="Request"/> <xsd:enumeration value="Problem"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="PriorityType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="4"/> <xsd:enumeration value="3"/> <xsd:enumeration value="2"/> <xsd:enumeration value="1"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="SourceType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Phone"/> <xsd:enumeration value="Requester"/> <xsd:enumeration value="Email"/> <xsd:enumeration value="Web"/> <xsd:enumeration value="NMP"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="SubmitResponse" type="s:OutputMapping"/> <xsd:complexType name="OutputMapping"> <xsd:sequence> <xsd:element name="StagingTable_ID" type="xsd:string"/> <xsd:element name="HelpDesk_ID" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:element name="AuthenticationInfo" type="s:AuthenticationInfo"/> <xsd:complexType name="AuthenticationInfo"> <xsd:sequence> <xsd:element name="userName" type="xsd:string"/> <xsd:element name="password" type="xsd:string"/> <xsd:element minOccurs="0" name="authentication" type="xsd:string"/> <xsd:element minOccurs="0" name="locale" type="xsd:string"/> <xsd:element minOccurs="0" name="timeZone" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="SubmitSoapOut"> <wsdl:part element="s:SubmitResponse" name="parameters"/> </wsdl:message> <wsdl:message name="SubmitSoapIn"> <wsdl:part element="s:Submit" name="parameters"/> </wsdl:message> <wsdl:message name="ARAuthenticate"> <wsdl:part element="s:AuthenticationInfo" name="parameters"/> </wsdl:message> <wsdl:portType name="gnHPD_Staging_Table_Submit_GenericPortType"> <wsdl:operation name="Submit"> <wsdl:input message="s:SubmitSoapIn"/> <wsdl:output message="s:SubmitSoapOut"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="gnHPD_Staging_Table_Submit_GenericSoapBinding" type="s:gnHPD_Staging_Table_Submit_GenericPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Submit"> <soap:operation soapAction="urn:gnHPD_Staging_Table_Submit_Generic/Submit" style="document"/> <wsdl:input> <soap:header message="s:ARAuthenticate" part="parameters" use="literal"></soap:header> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="gnHPD_Staging_Table_Submit_GenericService"> <wsdl:documentation>Generic Submit for HD</wsdl:documentation> <wsdl:port binding="s:gnHPD_Staging_Table_Submit_GenericSoapBinding" name="gnHPD_Staging_Table_Submit_GenericSoap"> <soap:address location="http://gremedydev:9090/midtier/services/ARService?server=gremedydev&webService=gnHPD_Staging_Table_Submit_Generic"/> </wsdl:port> </wsdl:service> </wsdl:definitions> Here's my php code: $params = array( "Submitter_UNIX"=>'myunix', "Source"=>'Web', "Summary"=>'Test1', "Description"=>'Test1', "Category"=>'test services', "Type"=>'test solutions', "Item"=>'Problem', "Assigned_To_Group"=>'test solutions', "Case_Type"=>'Problem', "Priority"=>'4', "AutoPush" => 'Auto Push', "Details"=>'Test Details', "Entry_Number"=>'', "Integration_Application"=>'MyMobile' ); $client = new SoapClient('http://gremedydev:9090/midtier/WSDL/gremedydev/gnHPD_Staging_Table_Submit_Generic',array('trace' => 1 )); $result = $client->Submit($params); I get this reply Code: [Select] Fatal error: Uncaught SoapFault exception: [ns1:Server.userException] MessageType: 2 MessageNum: 149 MessageText: A user name must be supplied in the control record AppendedText: in D:\Inetpub\wwwroot\myMobile\test\testwsdl2.php:29 Stack trace: #0 [internal function]: SoapClient->__call('Submit', Array) #1 D:\Inetpub\wwwroot\myMobile\test\testwsdl2.php(29): SoapClient->Submit(Array) #2 {main} thrown in D:\Inetpub\wwwroot\myMobile\test\testwsdl2.php on line 29 The only thing I can think of missing here is headers but I have no idea how to configure that. Any insight is greately appreciated! I have a class called cid which contains these functions: Code: [Select] public function UpdateDeliveryAddress($orderNumber, $deliveryaddress) { $sql = "UPDATE `CIDOrders` SET `DeliveryAddress` = '" . mysql_real_escape_string($deliveryaddress) . "' WHERE `CIDOrderNumber` = " . $orderNumber . ";"; mysql_select_db(DB_DATABASE_NAME, $this->conn); return mysql_query($sql, $this->conn); } public function UpdateInvoiceAddress($orderNumber, $invoiceAddress) { $sql = "UPDATE `CIDOrders` SET `InvoiceAddress` = '" . mysql_real_escape_string($invoiceaddress) . "' WHERE `CIDOrderNumber` = " . $orderNumber . ";"; mysql_select_db(DB_DATABASE_NAME, $this->conn); return mysql_query($sql, $this->conn); } It is called in a page called create order. Code: [Select] / Add a new delivery address to the order $cid->UpdateDeliveryAddress($_POST['orderNumber'], $_POST['deliveryaddress']); // Add invoice address to the order $cid->UpdateInvoiceAddress($_POST['orderNumber'], $_POST['invoiceaddress']); I get a call to undefined method error. Can anyone help me. thank you Call to undefined method skin_register::show_lostpass_form() in /var/www/sources/reg.php on line 1042 1042: Code: [Select] $this->output = $this->html->show_lostpass_form(); my html function show_lostpass_form(); is Code: [Select] function show_lostpass_form_manual() { global $ibforums; return <<<EOF <div class="tablepad">{$ibforums->lang['dumb_text']}</div> <div class="pformstrip">{$ibforums->lang['complete_form']}</div> <table class="tablebasic"> <tr> <td class="pformleft"><strong>{$ibforums->lang['user_id']}</strong></td> <td class="pformright"><input type='text' size='32' maxlength='32' name='uid' class='forminput' /></td> </tr> <tr> <td class="pformleft"><strong>{$ibforums->lang['val_key']}</strong></td> <td class="pformright"><input type='text' size='32' maxlength='50' name='aid' class='forminput' /></td> </tr> EOF; } why this error not going away? :O I'm trying to get some data from an API with php-cURL. I went to Chrome Developer Tools and copied as cURL (as I usually do): curl 'https://api.domain.co/data/network.php?action=balance&id=#####' -H 'authority: api.domain.co' -H 'pragma: no-cache' -H 'cache-control: no-cache' -H 'accept: application/json, text/javascript, */*; q=0.01' -H 'sec-fetch-dest: empty' -H 'api_token: #######################' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36' -H 'origin: https://app.domain.com' -H 'sec-fetch-site: cross-site' -H 'sec-fetch-mode: cors' -H 'referer: https://app.domain.com/' -H 'accept-language: en-US;q=0.9,en;q=0.8,de;q=0.7,ru;q=0.6,en-GB;q=0.5' --compressed I converted the code to php-cURL and placed it in my page: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.domain.co/data/network.php?action=balance&id=#####'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); $headers = array(); $headers[] = 'authority: api.domain.co'; $headers[] = 'pragma: no-cache'; $headers[] = 'cache-control: no-cache'; $headers[] = 'accept: application/json, text/javascript, */*; q=0.01'; $headers[] = 'fec-fetch-dest: empty'; $headers[] = 'api_token: #######################'; $headers[] = 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'; $headers[] = 'origin: https://app.domain.com'; $headers[] = 'sec-fetch-site: cross-site'; $headers[] = 'sec-fetch-mode: cors'; $headers[] = 'referer: https://app.domain.com/'; $headers[] = 'accept-language: en-US;q=0.9,en;q=0.8,de;q=0.7,ru;q=0.6,en-GB;q=0.5'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); print_r($result); And I got the following response: {"message":"Forbidden"} I played around with the headers and other cURL parameters, but with no success. Then I said I should try with Postman, and imported the code from Chrome to Postman, and voilà, it worked. At this point, I thought that maybe I wasn't converting the code properly. So I took the code from Postman Code Generator as PHP - cURL and placed it in my page, only to get the same result as befo $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.domain.co/data/network.php?action=balance&id=#####", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "authority: domain.co", "pragma: no-cache", "cache-control: no-cache", "accept: application/json, text/javascript, */*; q=0.01", "sec-fetch-dest: empty", "api_token: #######################", "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36", "origin: https://app.domain.com", "sec-fetch-site: cross-site", "sec-fetch-mode: cors", "referer: https://app.domain.com/", "accept-language: en-US;q=0.9,en;q=0.8,de;q=0.7,ru;q=0.6,en-GB;q=0.5" ), )); $response = curl_exec($curl); curl_close($curl); echo $response; Again I tried to play with different headers (Also checked in Postman what headers are mandatory and tried only with those - but nothing). PS: I have cleared my cache and cookies, also tried with different browsers and different user-agent. I am using this method for many other API's, but with this one, I can't figure out what I'm doing wrong I'm working on an application and it seems that the else block is being executed no matter what in the following if statement. My question (which seems really basic and like I should know the answer but I can't seem to remember) is if you have an object instance in an if statement, how does that resolve? Will it resolve to true because there is an object there? I assume/think that would be the behaviour but I can't remember. Also, I'll point out the class I'm working with is Zend_Mail. From my understanding the send method will return an instance of $this upon success and will throw an exception on failure. The mail is being sent but the else block is executing anyway. I may just throw it in a try catch if that's better. Code: [Select] if ($mail->send()) { return true; } else { $NOTICE++; $NOTICESTR[] = "We were unable to e-mail an e-mail notification <strong>".$to["email"]."</strong>.<br /><br />A system administrator was notified of this issue, but you may wish to contact this learner manually and let them know their accommodation has been removed."; application_log("error", "Unable to send accommodation notification to [".$to["email"]."] / type [".$type."]. Zend_Mail said: ".$mail->ErrorInfo); } Thanks in advance. I'll check back in a bit. class MyDisplay { function displayToday() { $today = "Thursday"; { echo $today; } } function displayTomorrow() { $tomorrow = "Friday"; { echo $tomorrow; } } } $disp = new MyDisplay(); echo $disp->displayToday(); echo displayTomorrow();//fails is I have $disp->I simplified my code for explanation. One class with two methods. When I try to use the method I get this error. Fatal error: Call to undefined method MyDisplay::displayTomorrow() Edited by mallen, 05 June 2014 - 02:46 PM. Well I have a library file class_database.php which defines a class called 'database' and a method called 'get' to retrieve database info. It was originally designed to return a two-dimensional array with the format of $array['index']['associative']. Right now I want to change this so as to return a result, which can then be used in other script files to retrieve data by using the fetch_array() method after getting this result. It doesnt work though, and I got this error 'Call to undefined method mysqli_stmt::get_result()', which confuses me... The two methods get() and _buildQuery are shown below, please help me figure out how to return an Mysql result so that I can use while($row = $db->get()->fetch_array()) on it with flexibility... The method get() Code: [Select] public function get($tableName, $numRows = NULL) { $this->_query = "SELECT * FROM $tableName"; $stmt = $this->_buildQuery($numRows); $stmt->execute(); $results = $stmt->get_result(); $this->reset(); return $results; } The method _buildQuery is shown below: Code: [Select] protected function _buildQuery($numRows = NULL, $tableData = NULL) { (gettype($tableData) === 'array') ? $hasTableData = true : $hasTableData = false; (!empty($this->_where )) ? $hasConditional = true : $hasConditional = false; // Did the user call the "where" method? if (!empty($this->_where)) { // if update data was passed, filter through and create the SQL query, accordingly. if ($hasTableData) { $i = 1; $pos = strpos($this->_query, 'UPDATE'); if ( $pos !== false) { foreach ($tableData as $prop => $value) { // determines what data type the item is, for binding purposes. $this->_paramTypeList .= $this->_determineType($value); // prepares the reset of the SQL query. ($i === count($tableData)) ? $this->_query .= $prop . ' = ?': $this->_query .= $prop . ' = ?, '; $i++; } } } //Prepair the where portion of the query $this->_query .= ' WHERE '; $i = 1; foreach ($this->_where as $column => $value) { // Determines what data type the where column is, for binding purposes. $this->_whereTypeList .= $this->_determineType($value); // Prepares the reset of the SQL query. ($i === count($this->_where)) ? $this->_query .= $column . ' = ?': $this->_query .= $column . ' = ? AND '; $i++; } } // Determine if is INSERT query if ($hasTableData) { $pos = strpos($this->_query, 'INSERT'); if ($pos !== false) { //is insert statement $keys = array_keys($tableData); $values = array_values($tableData); $num = count($keys); // wrap values in quotes foreach ($values as $key => $val) { $values[$key] = "'{$val}'"; $this->_paramTypeList .= $this->_determineType($val); } $this->_query .= '(' . implode($keys, ', ') . ')'; $this->_query .= ' VALUES('; while ($num !== 0) { ($num !== 1) ? $this->_query .= '?, ' : $this->_query .= '?)'; $num--; } } } // Did the user set a limit if (isset($numRows)) { $this->_query .= " LIMIT " . (int) $numRows; } // Prepare query $stmt = $this->_prepareQuery(); // Prepare table data bind parameters if ($hasTableData) { $this->_bindParams[0] = $this->_paramTypeList; foreach ($tableData as $prop => $val) { array_push($this->_bindParams, &$tableData[$prop]); } } // Prepare where condition bind parameters if($hasConditional) { if ($this->_where) { $this->_bindParams[0] .= $this->_whereTypeList; foreach ($this->_where as $prop => $val) { array_push($this->_bindParams, &$this->_where[$prop]); } } } // Bind parameters to statment if ($hasTableData || $hasConditional){ call_user_func_array(array($stmt, 'bind_param'), $this->_bindParams); } return $stmt; } So i read the docs on this and it said to create a callback function and use ini_set to set the function. I am trying to serialize an array with the class inside the array Code: [Select] $dd_normal_button = array ( 'dd_normal_button_display' => array ( 'dd_button_digg' => __PHP_Incomplete_Class::__set_state(array( '__PHP_Incomplete_Class_Name' => 'DD_Digg', 'buttonLayout' => array ( 'Wide' => 'DiggWide', 'Normal' => 'DiggMedium', 'Compact' => 'DiggCompact', 'Icon' => 'DiggIcon', ), ) ) ) ); So then I try Code: [Select] serialize($dd_normal_button); and I get the error. Any ideas/suggestions. Thanks So I have this code that generates a random ID class Session { var $username; //Username given on sign-up var $userid; //Random value generated on current login ... ... function Session(){ $this->time = time(); $this->startSession(); } ... ... $this->userid = $_SESSION['userid'] = $this->generateRandID(); ... ... function generateRandID(){ return md5($this->generateRandStr(16)); } and when it runs i get this error... Fatal error: Call to undefined method Session::generateRandID() Any ideas? HI guys, i am using 'Spreadsheet excel writer' to write form data into an excel sheet. below is my code snippet, uses to add worksheets, iam getting an error, which is really breaking me. can u please have a look at this, and help me. Code: [Select] <?php $xml = simplexml_load_file("featureDetail.xml"); require_once 'Spreadsheet/Excel/Writer.php'; $excel = new Spreadsheet_Excel_Writer(); $sheet =& $excel->addWorksheet('Home'); $sheet->setColumn(0,0,29); foreach($xml->FEATURE as $feature) { global $excel; $value=html_entity_decode($feature->NAME); echo " Value = $value"; echo "<br>"; $sheet123 =& $excel->addWorksheet('$value'); $sheet123->setColumn(0,0,29); } foreach($xml->FEATURE as $feature) { $sheet =& $excel->addWorksheet(html_entity_decode($feature->NAME)); $sheet->setColumn(0,0,29); } ?> Fatal error: Call to undefined method PEAR_Error::setColumn() in D:\xampp\htdocs\Release9.0\example.php on line 14 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321957.0 Hello, I have no idea where to post this but basically I am trying to create a facebook application using a "Building Facebook Applications For Dummies" book but I am stuck on the first paragraph! This is the appinclude.php file: Code: [Select] <?php require_once '../client/facebook.php'; // *** Add your Facebook API Key, Secret Key, and Callback URL here *** $appapikey = '<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>'; $appsecret = '<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>'; $appcallbackurl = '<http://projectstratos.com/facebook/live/>'; // Connect to Facebook, retrieve user $facebook = new Facebook($appapikey, $appsecret); // $user = $facebook->require_login(); OLD $user = $facebook->get_loggedin_user(); $is_logged_out = !$user; // Exception handler for invalid session_keys try { // If app is not added, then attempt to add if (!$facebook->api_client->users_isAppAdded()) { $facebook->redirect($facebook->get_add_url()); } } catch (Exception $ex) { // Clear out cookies for app and redirect user to a login prompt $facebook->set_user(null, null); $facebook->redirect($appcallbackurl); } ?> And this is the index.php file: Code: [Select] <h1>Watch Project Stratos Live!</h1> <?php require_once 'appinclude.php'; echo "<p>Your user id is: $user</p>"; echo "<p>Your name is: <fb:name uid=\"$user\" useyou\"false\" /></p>"; echo "<p>You have several freinds: </p>"; $friends = $facebook->app_client->friends_get(); echo "<ul>"; foreach ($friends as $friend) { echo "<li><fb:name uid=\"$freind\" useyou\"false\" /></li>"; } echo "</ul>"; ?> The facebook.php is the current fbml version (v2.1.2-4 I think) and the content in the h1 tag is echoed however after that there is the following errror message: Code: [Select] Fatal error: Call to undefined method Facebook::get_loggedin_user() in /xxxxxx/xxxxxx/xxxxxx/xxxx/xxxxxxxxxxxxxxxxxxxxxx/facebook/live/appinclude.php on line 12 I have mo idea what the problem could be! I have tried changing get_loggedin_user to getUser() but I just get another error, this is aparently (according to another forum) because I "forgot" to add get_loggedin_user. Thanks in advance, Cameron This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 Using simple mail.php script. Yet I am getting the dreaded Fatal error: Call to undefined method Mail::AddAttachment() in ... error
"Fatal error: Call to undefined method Mail::AddAttachment() in \\...\www\mail.php on line 59"
This is mail.php
<?php class Mail { var $parts; var $to; var $cc; var $bcc; var $from; var $headers; var $subject; var $body; var $html; var $host; var $port; function __construct() { $this->parts = array(); $this->to = ""; $this->cc = ""; $this->bcc = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; $this->html = true; } function buildMultipart() { $boundry = "HKC".md5(uniqid(time())); $multipart = "Content-Type: multipart/mixed; boundary = \"$boundry\"\n\n"; $multipart .= "This is a MIME encoded message.\n\n--$boundry"; for($i = sizeof($this->parts)-1; $i >= 0; $i--) { $multipart .= "\n".$this->buildMessage($this->parts[$i])."--$boundry"; } return $multipart .= "--\n"; } function getMail($complete = true) { $mime = ""; if(!empty($this->from)) { $mime .= "From: ".$this->from."\n"; } if(!empty($this->headers)) { $mime .= $this->headers."\n"; } if($complete) { if(!empty($this->cc)) { $mime .= "Cc: ".$this->cc."\n"; } if(!empty($this->bcc)) { $mime .= "Bcc: ".$this->bcc."\n"; } if(!empty($this->subject)) { $mime .= "Subject: ".$this->subject."\n"; } } if(!empty($this->body)) { $this->AddAttachment($this->body,"",($this->html?"text/html":"text/plain")); } $mime .= "MIME-Version: 1.0\n".$this->buildMultipart(); return $mime; } function send() { if(!empty($this->cc)) { $mime = $this->getMail(true); } else { $mime = $this->getMail(false); } if(!empty($this->host)) { ini_set("SMTP",$this->host); } return mail($this->to,$this->subject,$this->body,$mime); } } ?>And this is the program that makes the call: <?php if (isset($_POST["email"])) { $email = $_POST["email"]; $email= str_replace("'", "''", $email); require_once('../database.php'); $sql="select fa_id,name from freeagents where email='".$email."'"; $emailSearch = mssqlquery($sql); if (!mssqlhasrows($emailSearch)) { mssqlclose(); header("Location: http://www.baltimorebeach.com"); exit(); } $row = mssqlfetchassoc($emailSearch); mssqlclose(); $salt=$row["fa_id"].".baltimorebeach."; $check=hash('ripemd160', $salt.$email); $strMailBody = <<<MAILBODY Hi $row[name], <br><br> A request was made to change your Baltimore beach volleyball free agent registration information. <br><br> If you want to update your registration information click on this link: http://www.baltimorebeach.com/FreeAgents/registerfreeagent.php?email=$email&check=$check <br><br> To remove your name from the Free Agent list deselect all the checkboxes when you update your information. MAILBODY; require_once('../mail.php'); $message = new Mail(); $message->from = "noreply@baltimorebeach.com"; $message->to = $email; $message->subject = "Baltimore Beach Volleyball Free Agent Registration Update Link"; $message->body = $strMailBody; $message->html = true; $message->send(); } ?> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script> <style type="text/css"> label.error { color:red; } input.error { border:1px solid red; } </style> <script type="text/javascript"> $().ready(function () { // validate registration form on keyup and submit $("#emailform").validate({ rules: { email: { required: true, email: true } }, messages: { email: { required: "Please enter an email address", email: "Please enter a valid email address" } } }); }); </script> </head> <body> To update your free agent registration information enter your email to send yourself a baltimorebeach.com url link that will allow you to access your own registration details. <br> To remove yourself from the free agent list just deselect all the leagues you have previously selected when updating your information. <br> <br> <?php if (!isset($_POST["email"])) { ?> <form id="emailform" action="sendlink.php" method="post"> E-Mail: <input type="text" id="email" name="email" value=""/> <br> <input type="submit" id="sumbit" value="Send"> </form> <?php } else { echo "E-Mail Sent. "."You will receive an email with the update link at the email address your requested shortly"; } ?> </body> </html>I did not write this code, however the person who did is no longer available to me. I can't seem to figure out how to remove this error. Thanks so much! Hello, I've been following google maps with php/mysql turorial http://code.google.com/apis/maps/articles/phpsqlajax.html I've come to my phpsqlajax_genxml.php file which as the google code has it like this: <?php require("phpsqlajax_dbinfo.php"); // Start XML file, create parent node $doc = domxml_new_doc("1.0"); $node = $doc->create_element("markers"); $parnode = $doc->append_child($node); // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->create_element("marker"); $newnode = $parnode->append_child($node); $newnode->set_attribute("name", $row['name']); $newnode->set_attribute("address", $row['address']); $newnode->set_attribute("lat", $row['lat']); $newnode->set_attribute("lng", $row['lng']); $newnode->set_attribute("type", $row['type']); } $xmlfile = $doc->dump_mem(); echo $xmlfile; ?> I started with this but was getting errors at line 1!! I looked around abit on the net and found i should change $doc = domxml_new_doc("1.0"); to this $doc = new DOMDocument('1.0'); Then i got errors abour creating the elements, i looke on php.net and it looked like i needed to change $node = $doc->create_element("markers"); $parnode = $doc->append_child($node); $newnode->set_attribute("name", $row['name']); To this: $node = $doc->createElement('markers'); $parnode = $doc->appendChild($node); $newnode->setAttribute ('name', $row['name']); This at least got my code further down the page until the very last statment: $xmlfile = $doc->dump_mem(); Here i'm getting this error "Fatal error: Call to undefined method DOMDocument::dump_mem()" along with "Warning: Cannot modify header information - headers already sent" I havent even looked at the warning i just tried to fix the fatal error. Again i looked around the web and forums and php.net and thought maybe i need to set the value to "true" but it still got a fatal error. I looked on php.net and in there examples for dump_mem() and they had the nodes set_attribute create_element and append_child. Which confused me as that was what i used originally just following the google script and that got me the error right away "Fatal error to undefined method DOMDocument::create" Can anybody point out whats going wrong? This is my script that I am using <?php require('connect.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>phpsqlajax_genxml.php</title> </head> <body> <?php // Start XML file, create parent node $doc = new DOMDocument('1.0'); $node = $doc->createElement('markers'); $parnode = $doc->appendChild($node); // Select all rows in markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die ('Invalid query: ' . mysql_error()); } header('Content-type: text/xml'); // Iterate through the rows, addind xml nodes for each while ($row = mysql_fetch_assoc($result)) { // Add to XML document node $node = $doc->createElement('marker'); $newnode = $parnode->appendChild($node); $newnode->setAttribute ('name', $row['name']); $newnode->setAttribute ('address', $row['address']); $newnode->setAttribute ('lat', $row['lat']); $newnode->setAttribute ('lng', $row['lng']); $newnode->setAttribute ('type', $row['type']); } $xmlfile = $doc->dump_mem(); echo $xmlfile; ?> </body> </html> And the google code is on the link in posted in the messge also but this is theres both of which fail for Fatal errors either on the dump_mem() or new DOMDocument respecitvaley : <?php require("phpsqlajax_dbinfo.php"); // Start XML file, create parent node $doc = domxml_new_doc("1.0"); $node = $doc->create_element("markers"); $parnode = $doc->append_child($node); // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->create_element("marker"); $newnode = $parnode->append_child($node); $newnode->set_attribute("name", $row['name']); $newnode->set_attribute("address", $row['address']); $newnode->set_attribute("lat", $row['lat']); $newnode->set_attribute("lng", $row['lng']); $newnode->set_attribute("type", $row['type']); } $xmlfile = $doc->dump_mem(); echo $xmlfile; ?> Thanks to anybody who can help me out I can call the following function successfully as a single php program // Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. Hello, I've been trying this for hours now, looking at different examples and trying to change them to work for me, but with no luck... This is what I am trying to do: I have a simple form with: - 1 input field, where I can enter a number - 1 Submit Button When I enter a number into the field and click submit, I want that number to be send to the php file that is in the ajax call, then the script will take that number and run a bunch of queries and then return a new number. I want that new number to be used to call the php script via ajax again, until no number is returned, or something else is returned like the word "done" or something like that, at which point is simply makes an alert or populated a div with a message... The point is, that depending on the number entered it could take up to an hour to complete ALL the queries, so I want the script that is called to only run a fixed amount of queries at a time and then return the number it is currently at (+1), so that it can continue with the next number when it is called again. I would like to use jquery, but could also be any other way, as long as I get this to work. I already have the php script completed that needs to be called by the ajax, it returns a single number when being called. Thank you, vb If a class has a constructor but also has a static method, if I call the static method does the constructor run so that I can use an output from the constructor in my static method? --Kenoli |