PHP - Bangging My Head Against Wsdl / Soap Call
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! Similar TutorialsI have a project at work to create a web service, using SOAP and have been provided a WSDL file to work from. I have never created a SOAP server before and I'm having some difficulty finding a good tutorial on building a SOAP server using a WSDL file. Can anyone provide any information, guidance, or links to some good materials to get started? Preferably a step by step tutorial that builds a SOAP server, using WSDL. Thanks! Hi y'all. I've been looking at this for two days now and my head is starting to hurt from it.
I'm trying to integrate with an existing web service for client log-in and having trouble getting it done and Google is being very little help at this point. Here's the code, annotated where necessary:
namespace myNamespace; MyClass{ private $_apiLoginAddr = 'http://xxx.xxx.xxx.xxx:xxxx/ServiceAddress/Login.asmx?wsdl'; public function logIn($email,$id){ /* // these work... $testClient = new \SoapClient('http://www.webservicex.com/CurrencyConvertor.asmx?wsdl',array('trace'=>1,'exceptions'=>1)); $resp = $testClient->ConversionRate(array('FromCurrency'=>'USD','ToCurrency'=>'CAD')); print($resp->ConversionRateResult); $testClientAWS = new \SoapClient('http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl',array('trace'=>1,'exceptions'=>1)); $resp = $testClientAWS->ItemLookup(array('ItemID'=>'1430260319')); var_dump($resp); $testClientP = new \SoapClient('https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl',array('trace'=>1,'execptions'=>1)); print_r($testClientP->__getFunctions()); die(); */ // turning off caching because apparently it's sometimes an issue... ini_set('soap.wsdl_cache_enbled','0'); ini_set('soap.wsdl_cache_ttl','0'); // this doesn't work even a little bit... try{ $creds = array( 'trace' => 1, 'exceptions' => 1, 'cache_wsdl' => 'WSDL_CACHE_NONE', 'soap_version' => SOAP_1_1, ); $client = new \SoapClient($this->_apiLoginAddr,$creds); $results = $client->WebsiteLogin(array('_Password'=>$id,'_UserName'=>$email)); var_dump($client->__getLastRequest()); print('break'); var_dump($client->__getLastResponse()); }catch(\SoapFault $e){ print('Exception thrown!'); var_dump($e); die(); } print('Succesfully completed call!'); var_dump($results); die(); } }Using this code, the browser churns for about a minute before I get the error "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xxx.xxx.xxx.x...ceAddress/Login.asmx' : failed to load external entity "http://xxx.xxx.xxx.x...ess/Login.asmx", with or without the call to WebsiteLogin(). Now, I've also tried a non-wsdl version where I replaced the credentials array and SoapClient instantiation with the following: try{ $creds = array( 'trace' => 1, 'exceptions' => 1, 'cache_wsdl' => 'WSDL_CACHE_NONE', 'location' => $this->_apiLoginAddr, 'uri' => 'http://tempuri.org', 'soap_version' => SOAP_1_1, ); $client = new \SoapClient(null,$creds); $results = $client->WebsiteLogin(array('_Password'=>$id,'_UserName'=>$email)); /* see previous code block */Using this approach, my browser again churns for about a minute before I get the error "Could not connect to host". If I don't actually try to log in using the service's WebsiteLogin() function, SoapClient doesn't throw an error on this one and reports a successfully completed call. Which does me no good at all, because my users can't log in if I don't call the WebsiteLogin() function. I can visit the end-point directly in my browser and it's definitely there and active, and SoapUI has no problem at all with the request or the response. I've tried uncommenting the open_ssl.dll in my php.ini, turning the wsdl caching options off in the php.ini directly, and pretty much everything short of ritual sacrifice to no avail. My log in form is sending the credentials via AJAX to the logIn() method above, and all this is happening in a WordPress site. However, as the webservicex, webservices.amazon.com, and pilot.prove-uru.co.uk soap calls all complete successfully, I don't think that's an issue. I've spoken with the maintainer of the service gateway and he swears we're not blacklisted through the firewall, but nothing is working. Anybody come across anything similar? Or have better Google skills that can actually find an applicable answer? Or have any ideas at all? 'Cause I'm at a loss... Hello, I'm working with a website's soap services to communicate with their servers, They have sent me a sample code of .Net that works properly for all methods of their web services, But while I'm trying to use the same web services via php-soap the functions that has array of string as a parameter for a method doesn't work at all, ( the other functions work fine ) Here is the sample code of .Net: Code: [Select] webServiceType ws = new webServiceType(); string res = ws.methodX("username", "password", new string[] { "x" , "y" }); but this code in PHP doesn't work fine and throw an exception $client = new SoapClient("http://webserviceURL.com?WSDL",array("features" => SOAP_SINGLE_ELEMENT_ARRAYS)); $response = $client->methodX("username","password",array ( "x" , "y" )); Any suggestion on how to pass an array of string to a method via soap- WSDL? Hi, Help would be very appreciative I am doing some preliminary testing for future projects. A company we are working with supplied us with a wsdl file to communicate with their system. I want to use PHP to run functions in the wsdl file but I got stuck after calling a function and I get no response back. Below is my test snippet PHP code. Below the PHP code is the wsdl file (also attached change the extension from .txt to .wsdl before using it). When I run the php code from command line (linux server) I get a "Segmentation fault" back. I am assuming that the error is coming from the wsdl file. I am not high fly on wsdl code and I would not really know what I'm doing if I started chopping and dicing the wsdl file. <?php $client = new SoapClient("http://172.21.1.24:7070/comactivity/axis2services/OrderEntryWebService?wsdl/"); //if the wsdl exist locally use //$client = new SoapClient("file.wsdl"); //echo var_export($client->__getFunctions(),true); $arr_head=array( "cuno" =>"1234", "ortp" =>"ORD", "faci" =>"M00", "rldt" =>"20110811" ); try { $arr = $client->__soapCall("addBatchHead", $arr_head); } catch (SoapFault $exception){ echo $exception; } ?> =========== WSDL file within these tags ============= <?xml version="1.0" encoding="utf-16"?> <wsdl:definitions xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns="http://services.web" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://services.web" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <wsdl:documentation>Order Entry Web Service</wsdl:documentation> <wsdl:types> <xs:schema attributeFormDefault="qualified" elementFormDefault="unqualified" targetNamespace="http://services.web"> <xs:element name="addBatchHead"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="cuno" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="ortp" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="faci" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="rldt" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="addBatchHeadResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="addBatchHeadReturn" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="addBatchLine"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="tempOrno" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="itno" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="orqt" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="whlo" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="dlsp" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="addBatchLineResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="addBatchLineReturn" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="confirm"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="tempOrno" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="confirmResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="confirmReturn" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </wsdl:types> <wsdl:message name="addBatchLineRequest"> <wsdl:part name="parameters" element="ns:addBatchLine" /> </wsdl:message> <wsdl:message name="confirmRequest"> <wsdl:part name="parameters" element="ns:confirm" /> </wsdl:message> <wsdl:message name="confirmResponse"> <wsdl:part name="parameters" element="ns:confirmResponse" /> </wsdl:message> <wsdl:message name="addBatchHeadResponse"> <wsdl:part name="parameters" element="ns:addBatchHeadResponse" /> </wsdl:message> <wsdl:message name="addBatchLineResponse"> <wsdl:part name="parameters" element="ns:addBatchLineResponse" /> </wsdl:message> <wsdl:message name="addBatchHeadRequest"> <wsdl:part name="parameters" element="ns:addBatchHead" /> </wsdl:message> <wsdl:portType name="OrderEntryWebServicePortType"> <wsdl:operation name="addBatchLine"> <wsdl:input wsaw:Action="urn:addBatchLine" message="ns:addBatchLineRequest" /> <wsdl:output wsaw:Action="urn:addBatchLineResponse" message="ns:addBatchLineResponse" /> </wsdl:operation> <wsdl:operation name="addBatchHead"> <wsdl:input wsaw:Action="urn:addBatchHead" message="ns:addBatchHeadRequest" /> <wsdl:output wsaw:Action="urn:addBatchHeadResponse" message="ns:addBatchHeadResponse" /> </wsdl:operation> <wsdl:operation name="confirm"> <wsdl:input wsaw:Action="urn:confirm" message="ns:confirmRequest" /> <wsdl:output wsaw:Action="urn:confirmResponse" message="ns:confirmResponse" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="OrderEntryWebServiceHttpBinding" type="ns:OrderEntryWebServicePortType"> <http:binding verb="POST" /> <wsdl:operation name="addBatchLine"> <http:operation location="OrderEntryWebService/addBatchLine" /> <wsdl:input> <mime:content part="addBatchLine" type="text/xml" /> </wsdl:input> <wsdl:output> <mime:content part="addBatchLine" type="text/xml" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="addBatchHead"> <http:operation location="OrderEntryWebService/addBatchHead" /> <wsdl:input> <mime:content part="addBatchHead" type="text/xml" /> </wsdl:input> <wsdl:output> <mime:content part="addBatchHead" type="text/xml" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="confirm"> <http:operation location="OrderEntryWebService/confirm" /> <wsdl:input> <mime:content part="confirm" type="text/xml" /> </wsdl:input> <wsdl:output> <mime:content part="confirm" type="text/xml" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="OrderEntryWebServiceSoap11Binding" type="ns:OrderEntryWebServicePortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="addBatchLine"> <soap:operation soapAction="urn:addBatchLine" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="addBatchHead"> <soap:operation soapAction="urn:addBatchHead" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="confirm"> <soap:operation soapAction="urn:confirm" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="OrderEntryWebServiceSoap12Binding" type="ns:OrderEntryWebServicePortType"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="addBatchLine"> <soap12:operation soapAction="urn:addBatchLine" style="document" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="addBatchHead"> <soap12:operation soapAction="urn:addBatchHead" style="document" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="confirm"> <soap12:operation soapAction="urn:confirm" style="document" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="OrderEntryWebService"> <wsdl:port name="OrderEntryWebServiceHttpEndpoint" binding="ns:OrderEntryWebServiceHttpBinding"> <http:address location="http://172.21.1.24:7070/comactivity/axis2services/OrderEntryWebService/" /> </wsdl:port> <wsdl:port name="OrderEntryWebServiceHttpSoap12Endpoint" binding="ns:OrderEntryWebServiceSoap12Binding"> <soap12:address location="http://172.21.1.24:7070/comactivity/axis2services/OrderEntryWebService/" /> </wsdl:port> <wsdl:port name="OrderEntryWebService" binding="ns:OrderEntryWebServiceSoap11Binding"> <soap:address location="http://172.21.1.24:7070/comactivity/axis2services/OrderEntryWebService/" /> </wsdl:port> </wsdl:service> </wsdl:definitions> ============== End WSDL file =================== Thank you /Martin [attachment deleted by admin] 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. Hi 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 I was accessing a wsdl file, using php, using normal php SoapClient code. $soap=new SoapClient(WSDL_FILE_LOCATION); The code ran properly in localhost. But, when I uploaded the files in my free server 000webhost.com. I get the following error Fatal error: Class 'SoapClient' not found in /home/****/public_html/myfile.php on line 12 The error points to SoapClient(WSDL_FILE_LOCATION); line I couldn't understand the problem. Can someone please help me out? Thanks in advance Hi all, Hi, A consumer give me WSDL that describe SOAP messages in order to communicate together by Web services. The first WSDL is a webservice that I consume, no problem for this part. But the second one must be implemented in our side, a wsdl is provided to describe the ws that we must develop. The problem is that I don't know how to do? Is a tool exist to generate server code from a wsdl? should I develop from scratch and try to match the wsdl? Any clue will be welcome. Regards, Kyor I'm able to consume a local WSDL into PHP, and pass/return basic data successfully, but when I attempt to pass in objects that correspond to a complextype in the WSDL, I get the following error: SoapFault exception: [soapenv:Server] javax.xml.ws.WebServiceException: com.ibm.websphere.sca.ServiceRuntimeException: An error occurred while parsing native data: The error message is: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more.. Caused By: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more.: caused by: An error occurred while parsing native data: The error message is: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more.. Caused By: java.lang.IllegalArgumentException: Mismatched parameter count: expecting 1 items, but got more. in C:\wamp\www\SugarCE\testSOAPShawn.php:65 Stack trace: #0 [internal function]: SoapClient->__call('establishIdenti...', Array) #1 C:\wamp\www\SugarCE\testSOAPShawn.php(65): SoapClient->establishIdentity(Object(stdClass), Object(stdClass)) #2 {main} Here is the snippets from the WSDL: Code: [Select] <xsd:element name="establishIdentity"> − <xsd:complexType> − <xsd:sequence> − <xsd:element name="processId" nillable="true" type="xsd:string"> − <xsd:annotation> − <xsd:documentation> Identifies a specific instance of the dialogue process. Returned from the start() operation. </xsd:documentation> </xsd:annotation> </xsd:element> − <xsd:element name="identityAttributes" nillable="true" type="bons1:IdentityAttributes"> − <xsd:annotation> − <xsd:documentation> Key identifying attributes of a program participant. </xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> Here is my code with comments where the error occurs: <?php set_time_limit(0); require_once('nusoap.php'); $client = new SoapClient('C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP.wsdl', array('trace' => 1)); $start = $client->__soapCall('start', array(new SoapParam((string)'GenesisID', 'prefix')), array('soapaction' => 'C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP\start')); $processID = $start; $exchange = $client->__soapCall('exchangeOptions', array(new SoapParam($processID, 'processId')), array('soapaction' => 'C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP\exchangeOptions')); $identityAttributes = new StdClass(); $identityAttributes->IdentityAttributes = new StdClass(); $identityAttributes->IdentityAttributes->ssn = 41441414; $identityAttributes->IdentityAttributes->firstName = 'John2'; $identityAttributes->IdentityAttributes->lastName = 'Doe2'; $identityAttributes->IdentityAttributes->gender = 'MALE'; $identityAttributes->IdentityAttributes->birthDate = null; try{ $identity = $client->establishIdentity($processID, $identityAttributes); //ERROR } catch (SoapFault $f){ echo "ERROR!"; } $end = $client->__soapCall('stop', array(new SoapParam($processID, 'processId')), array('soapaction' => 'C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP\stop')); ?> Any assistance is greatly appreciated! Thanks. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 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. Ok, so I've read a few tutorials of OOP and have a basic understanding of how it works but where is it generally handy? I have a basic site created with PHP that consists of a form that submits data to MySQL and then lists the data from the MySQL database on another page. Kind of like a little online planner. I don't see how me converting my site to use OOP would help here. Maybe it's best for more complex situations such as a shopping cart where data needs to be shared across multiple pages? 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 first i have a standard html page. Just a form that submits data to upload.php http://pixel.imgboard.co.uk here is upload.php - note i know i have some weird echo's but ive been trying for 2 hours to get upload.php to display something... but nothing happens.. i cant even get it to output html. It just goes to upload.php and has a blank page. When i view source there is nothing there. Its literally a blank page. I can't work it out. someone please help. I'm going to crack up. <?php ini_set("display_errors", "1"); error_reporting(E_ALL); session_start(); include 'http://www.imgboard.co.uk/includes/functions.php'; $start = " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html> <head> <link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.imgboard.co.uk/style/pixel.css\" /> <title> Pixel - Image Hosting Beta</title> </head> <body> <div id =\"wrapper\"> <div class = 'titlebar'> <div class = 'titlebarlinkbox'> <a href = 'http://www.imgboard.co.uk'>Forum</a> <a href = 'http://www.imgboard.co.uk/Wiki.php'>Wikis</a> <a href = 'http://www.imgboard.co.uk/bulletins/0'>Bulletins</a> <a href = 'http://www.imgboard.co.uk/faq/0'>Faq's</a> </div> </div> <div class = \"logo\"></div> "; $end = " <div class = 'footerLinks'> Pixel @ 2010 - 2015 ! <br /> <a href = 'http://www.imgboard.co.uk'>Forum</a> | <a href = 'http://www.imgboard.co.uk/Wiki.php'>Wikis</a> | <a href = 'http://www.imgboard.co.uk/bulletins/0'>Bulletins</a> | <a href = 'http://www.imgboard.co.uk/faq/0'>Faq's</a> | <a href = 'http://www.imgboard.co.uk/pixel/report.php'>Report Image</a> </div> <div class = 'TnC'>Pixel is a Trademark of imgboard.co.uk. Please ensure all content uploaded is decent. No Taboo, cp, gore allowed. Porn / memes / misc themes all welcome. Any offensive content will be removed and deleted. Any misuse of the service and result in banning and in seviere cases prosecution.</div> </div> </body> </html> "; if(isset($_GET['uploadfile'])){ echo $start; echo $end; $validExtensions = array("png", "gif", "jpeg", "jpg", "bmp"); $ext = end(explode(".",$_FILES["image"]["name"])); $ext2= strtolower($ext); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)) && in_array($ext2,$validExtensions)) { //create a unique name. $newname = date(dmYhis); $newname .= rand(1111,9999); //preg replace non alpha numeric characters $fname = $_FILES['file']['name']; $newname = $newname . "." .$ext2; $location = "http://www.imgboard.co.uk/images/".$newname; //copy the file. if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){ //file uploaded create display Page. $t = $_POST['tags']; add_uploaded_image($location,$t); file_upload_display_page($location); } else{ die("Error Occured Moving File"); } } else{ die("wrong mime type"); } } function add_uploaded_image($link, $tags){ $c = protect($_COOKIE['supercookie']); $ip = $_SERVER['REMOTE_ADDR']; $t = protect($tags); mysql_query("INSERT INTO pixel (filename,tags,date,ip,cookie) VALUES ('$link','$t',NOW(),'$ip','$c')") or die(mysql_error()); } function file_upload_display_page($location){ echo " <table class = 'uploadTable' cellspacing = '0'> <tr> <td class = \"label\"> Image Uploaded: </td><td><img src = '$location' HEIGHT = '150'/> </td> </tr> <tr> <td class = \"label\"> Direct Link: </td><td><input type = 'text' name = 'file' id = 'file' value = '$location'/> </td> </tr> <tr> <td class = \"label\"> Html Code </td><td><input type = 'text' name = 'tags' value = \"<img src = '$location' ALT = 'Hosted On http://Pixel.imgboard.co.uk'/>\"/> </td> </tr> <tr> <td> <td class = \"label\"> BB Code: </td><td><input type = 'text' name = 'file' id = 'file' value = '[img]http://$location[/img]'/> </td> </td> </tr> </table> "; } Hi All, I am trying to use headers at the end of functions to put the user where they need to be. header("location: register.php?user_may_exist"); I understand how they work and their qwuirks. My issue is, in my head file, i am outputting which causes issues for the headers which come after. I have the following in head.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> <?php if(isset($currentPageTitle)){ echo $currentPageTitle; }else{ echo 'Cricket Club'; }; ?> </title> <?php if(isset($currentPageMeta)){ echo "<meta name='description' content='$currentPageMeta'>"; }else{ echo "<meta name='description' content='All the latest from CC'>"; }; ?> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Is there a better way for me to achieve this? how you doing guys. I'm having a little bit of a problem right now, with this thing call view-profile.php, i hope you guys know what it is, I'm new to php, so please try to help. it says the same thing everytime. Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\siteS\viewprofile.php on line 26 There was a problem accessing your profile <h3>Mismatch - View Profile</h3> <?php require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect('localhost', '***', '*****', '*****'); // Grab the profile data from the database if (!isset($_GET['user_id'])) { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '$user_id'"; } else { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); line26-----------> if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table>'; if (!empty($row['username'])) { echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>'; } if (!empty($row['first_name'])) { echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></tr>'; } if (!empty($row['last_name'])) { echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></tr>'; } if (!empty($row['gender'])) { echo '<tr><td class="label">Gender:</td><td>'; if ($row['gender'] == 'M') { echo 'Male'; } else if ($row['gender'] == 'F') { echo 'Female'; } else { echo '?'; } echo '</td></tr>'; } if (!empty($row['birthdate'])) { if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) { // Show the user their own birthdate echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>'; } else { // Show only the birth year for everyone else list($year, $month, $day) = explode('-', $row['birthdate']); echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>'; } } if (!empty($row['city']) || !empty($row['state'])) { echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>'; } if (!empty($row['picture'])) { echo '<tr><td class="label">Pictu </td><td><img src="' . MM_UPLOADPATH . $row['picture'] . '" alt="Profile Picture" /></td></tr>'; } echo '</table>'; if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) { echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } mysqli_close($dbc); ?> hey guys how you doing? I've been having a little bit of problem with php, in fact I'm frustrated, so please if you can help me in any tight of way, please do, I've been trying to make this php code work, but it won't, i don't know what I'm doing wrong, I'm new to php and mysql every time i try it, it saids one thing Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\siteN\approvescore.php:3) in C:\xampp\htdocs\siteN\authorize.php on line 17 <?php require_once ('authorize.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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guitar Wars - Approve a High Score</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Guitar Wars - Approve a High Score</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_GET['id']) && isset($_GET['date']) && isset($_GET['name']) && isset($_GET['score'])) { // Grab the score data from the GET $id = $_GET['id']; $date = $_GET['date']; $name = $_GET['name']; $score = $_GET['score']; $screenshot = $_GET['screenshot']; } else if (isset($_POST['id']) && isset($_POST['name']) && isset($_POST['score'])) { // Grab the score data from the POST $id = $_POST['id']; $name = $_POST['name']; $score = $_POST['score']; } else { echo '<p class="error">Sorry, no high score was specified for approval.</p>'; } if (isset($_POST['submit'])) { if ($_POST['confirm'] == 'Yes') { // Connect to the database $dbc = mysqli_connect('localhost', '999', 'adsd', 'guitarwars3'); // Approve the score by setting the approved column in the database $query = "UPDATE gtwars1 SET approved = 1 WHERE id = $id"; mysqli_query($dbc, $query); mysqli_close($dbc); // Confirm success with the user echo '<p>The high score of ' . $score . ' for ' . $name . ' was successfully approved.'; } else { echo '<p class="error">Sorry, there was a problem approving the high score.</p>'; } } else if (isset($id) && isset($name) && isset($date) && isset($score)) { echo '<p>Are you sure you want to approve the following high score?</p>'; echo '<p><strong>Name: </strong>' . $name . '<br /><strong>Date: </strong>' . $date . '<br /><strong>Sco </strong>' . $score . '</p>'; echo '<form method="post" action="approvescore.php">'; echo '<img src="' . GW_UPLOADPATH . $screenshot . '" width="160" alt="Score image" /><br />'; echo '<input type="radio" name="confirm" value="Yes" /> Yes '; echo '<input type="radio" name="confirm" value="No" checked="checked" /> No <br />'; echo '<input type="submit" value="Submit" name="submit" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="hidden" name="name" value="' . $name . '" />'; echo '<input type="hidden" name="score" value="' . $score . '" />'; echo '</form>'; } echo '<p><a href="admin.php"><< Back to admin page</a></p>'; ?> It's not usual I ask questions on here - I usually help rather than be helped but alas, this is really confusing ! Short Story (You can skip this to "Your Mission") Without going into unnecessary detail i'll try to explain what i'm trying to do; Take an array (example provided...) Array( // These must be here, they are initially read by the template parser to get a starting point. "data"=>Array( "template"=>"main", // Template to start from (base template) "content"=>"%custom_topmenu% <Br/>Table<Br/> %bigtablecustom1%", // replace %content% tag,Shows 2 Examples, A Custom Menu, and Main Table with Smaller Tables inside ), // Below is numerically indexed arrays of content that will replace tags in the above "content" item 0=>Array( "data"=>Array( "rkey"=>"%bigtablecustom1%", // MUST have this item "template"=>"bigtable_single", // MUST have this item 0=>Array( "%title%"=>"Some Table Heading", "%footer%"=>"Some Table Footer Message (author?)", "%content%"=>"Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%", "%title_note%"=>"Some Time and Date" ) ), 0=>Array( "data"=>Array( "rkey"=>"%smalltablecustom1%", "template"=>"smalltable_single", 0=>Array( "%title%"=>"Small Title", "%content%"=>"Some Small Content or Note" ) ) ), 1=>Array( "data"=>Array( "rkey"=>"%smalltablecustom2%", "template"=>"smalltable_single", 0=>Array( "%title%"=>"Small Title 2", "%content%"=>"Some Small Content or Note" ) ) ) ) 1=>Array( // The menu is dynamically created by the module using it's inherited protected methods. "data"=>Array( "rkey"=>"%custom_topmenu%", "template"=>"custom_topmenu", 0=>Array( "%item1_name%"=>"Sub-Link 1", "%item1_link%"=>"#", "%item2_name%"=>"Sub-Link 2", "%item2_link%"=>"#", "%item3_name%"=>"Sub-Link 3", "%item3_link%"=>"#", "%item4_name%"=>"Sub-Link 4", "%item4_link%"=>"#" ) ) ) ) Turn this array into a single document, basically collpase all items with their children in the parent code. The Problem (You can skip this to "Your Mission") Now to make it easier and to (try) to prevent cross-tag contamination (so templates dont replace content that is supposed to be there from other template files...) I have wrote a recursion function that fills out all the content and removes the content sub-array from the data arrays (half the job). So now I have a multi-dimensional array that needs collapsing into a single document (variable), I am getting confused with how to go through this array (below - not above) so that all the template items are "inserted" inside their parent array items. The Function I made // Recursive, goes through an array and converts any "data" into actual templates. (Puts the content into a template) private function parse_template_data_array($array){ // First let's count how many items are in the array that was passed to us $item_count = count($array); // This should never happen, each array should have at least a "data" array inside. if($item_count < 1){ // Template Parser Fatal Object Syntax Error exit("FATAL PARSER ERROR1"); // If there is only one item, we don't need to recurse (There are no "child" elements) and so we skip the recursive section. }else if($item_count == 1){ // No items to parse, move on // So there are some child elements we must recurse through. }else{ // So this loops each "Child" element and passes that array to this function (recurse), Once it's finished it saves the array (result). for($i=0;$i<($item_count-1);$i++){ // -1 from the count, 1 to get rid of the data array. $array[$i] = $this->parse_template_data_array($array[$i]); } } // This part does the initial "template expansion", it finds the template needed for this item and saves it with the content to this item. // So we count how many data items we have $dcount = count($array['data']); // Count Data Items (minimum of 2 - Each data array must have "rkey" and "template") // If there isn't at least two items then someone made a booboo. if($dcount < 2){ // Template Parser Fatal Object Syntax Error exit("FATAL PARSER ERROR2"); // Otherwise let's sort this content out (We don't check if we only have the 2 minimum items since templates might not have Tags to replace). }else{ // Load Template file using the "template" item in the data array. $template = $this->get_file($array['data']['template']); // Count the amount of data items (content) to replace tags inside the loaded template (If there is no content sub-array then put to 0 to skip the below part). $dstrcount = (isset($array['data'][0]))? count($array['data'][0]) : 0; // No template content, maybe no tags, just give the template content back. if($dstrcount < 1){ // No items to parse // We have some content to replace. }else{ // We need the keys of the content sub-array so we can use (a neat feature of) the str_replace function. $akeys = array_keys($array['data'][0]); $template = str_replace($akeys ,$array['data'][0],$template); } // Save the result into this array item so we can pass the whole item back (This is also what happens when it recurses above) $array['data']['content'] = $template; } // Return the result array. return $array; } The Array returned by the above function Array ( [data] => Array ( [rkey] => %cdb_res_tpl_blk% [template] => main [content] => <html><head></head><body>%custom_topmenu%<br />%bigtablecustom1%</body></html> ) [0] => Array ( [data] => Array ( [rkey] => %bigtablecustom1% [template] => bigtable_single [content] => "Some Table Heading"=>"Some Table Heading", "Some Table Footer Message (author?)"=>"Some Table Footer Message (author?)", "Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%"=>"Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%", "Some Time and Date"=>"Some Time and Date" ) [0] => Array ( [data] => Array ( [rkey] => %smalltablecustom1% [template] => smalltable_single [content] => "Small Title"=>"Small Title", "Some Small Content or Note"=>"Some Small Content or Note" ) ) [1] => Array ( [data] => Array ( [rkey] => %smalltablecustom2% [template] => smalltable_single [content] => "Small Title 2"=>"Small Title", "Some Small Content or Note"=>"Some Small Content or Note" ) ) ) [1] => Array ( [data] => Array ( [rkey] => %custom_topmenu% [template] => custom_topmenu [content] => "Sub-Link 1"=>"Sub-Link 1", "#"=>"#", "Sub-Link 2"=>"Sub-Link 2", "#"=>"#", "Sub-Link 3"=>"Sub-Link 3", "#"=>"#", "Sub-Link 4"=>"Sub-Link 4", "#"=>"#" ) ) ) Your mission (Should you choose to accept ofc ), is to take the above array and turn it into a single html variable, with all the child elements inside their parent templates by replacing the tags in the array. All the data required is in the array, all that is needed is to "collapse" the array. Things to bear in mind: %cdb_res_tpl_blk% - This is in the original template file, so the result of a successfull collapse will replace this tag with the result. Dont worry about this one [rkey] - This is the "Tag" to replace in the "parent" content. [template] - This is the template file. [content] - This is the content that needs to go inside the parent item. Expected Result <html><head></head><body>"Sub-Link 1"=>"Sub-Link 1", "#"=>"#", "Sub-Link 2"=>"Sub-Link 2", "#"=>"#", "Sub-Link 3"=>"Sub-Link 3", "#"=>"#", "Sub-Link 4"=>"Sub-Link 4", "#"=>"#"<br />"Some Table Heading"=>"Some Table Heading", "Some Table Footer Message (author?)"=>"Some Table Footer Message (author?)", "Some Content for the table with another rkey: "Small Title"=>"Small Title","Some Small Content or Note"=>"Some Small Content or Note" --- "Small Title 2"=>"Small Title","Some Small Content or Note"=>"Some Small Content or Note""=>"Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%", "Some Time and Date"=>"Some Time and Date"</body></html> I will be working on this myself and if I find a solution I will post here. It is just that the way I code is I put my idea in my head, then try to code it in my head categorically, but when I think I find a solution it seems there is a bug, such as it will only collpase the main element, the bigtable, and the first small table, it wont do the other small table and not the menu either so basically it doesnt recurse items in the same array, only those underneath it. I'm so close but yet...so far... THANK YOU for ANY light you can shed on this situation it's been bugging me for a few days now (admittely have not coded since my first attempt - so tired.) My Code I won't provide the code I've done for it now since it just flat-out doesn't work, I've lost the code that I mentioned earlier that was bugged I modified and to be perfectly honest can't be bothered to reproduce it (it won't get me anywhere). Hi all i provided a little code to someone in the misc thread to block users based on the user agent language as an alternative to ipaddresses. I used switch for this but the each line is executed even if my language code is different. Anyone have an idea why the switch code below is messing with me? <?php if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ){ $languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ); // $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3'; // need to remove spaces from strings to avoid error $languages = str_replace( ' ', '', $languages ); $languages = explode( ",", $languages ); // do something when you don't like the language switch ($languages[0]) { // first array item case 'ko': // korea echo "do something or set a variable"; break; case 'ru-md'||'ru': // russia echo "do something or set a variable"; break; case 'zh-cn'||'zh-hk'||'zh-mo'||'zh-sg'||'zh-tw'||'zh': // china echo "do something or set a variable"; break; case 'ne': // india echo "do something or set a variable"; break; default: echo "good"; } } ?> I changed it to a different code that uses in_array() which works, but i really would love to know why the above is not working as intended, i looked at php.net, but didn't found something nice in the comments. Maybe a guru out here that knows? <?php if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ){ $languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ); // $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3'; // need to remove spaces from strings to avoid error $languages = str_replace( ' ', '', $languages ); $languages = explode( ",", $languages ); // do something when you don't like the language $lang_array = array('ko','ru-md','ru','zh-cn','zh-hk','zh-mo','zh-sg','zh-tw','zh','ne'); if (in_array($languages[0], $lang_array)){ echo 'bad stuff'; }else{ echo 'good stuff'; } } ?> Thanks guys!! |