Nwlapcug.com


Come creare un'Area Client con PHP

Come creare un'Area Client con PHP


Si possono fare tanti progetti interessanti con PHP, ad esempio la creazione di un'area client in Twitter o qualsiasi client di applicazioni che si desiderano. PHP funziona bene con altre tecnologie, quali HTML, ColdFusion, Silverlight e WSDL (Web Service Description Language), così molti programmatori preferiscono usarlo per i loro progetti. Ora creiamo il nostro progetto di zona di client per sperimentare l'uso efficiente di PHP.

Istruzioni

1

Copiare e incollare il codice seguente all'ambiente PHP e salvarlo come "php/twitterSearchService.wsdl." Questo file deve essere nella directory principale Web per funzionare correttamente:

< wsdl:definitions xmlns = "http://schemas.xmlsoap.org/wsdl/"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:tns="http://schema.example.com"

targetNamespace="http://schema.example.com">

< wsdl:types >

&lt;xsd:schema targetNamespace="http://schema.example.com"/>

< / wsdl:types >

< nome messaggio = "getTwitterSearchRequest" >

&lt;part name="searchText" type="xsd:string"/>

&lt;part name="lastTwitterId" type="xsd:string"/>

< / messaggio >

< nome messaggio = "getTwitterSearchResponse" >

&lt;part name="getTwitterSearchReturn" type="xsd:string"/>

< / messaggio >

< nome: PortType = "twitterSearchServicePortType" >

&lt;wsdl:operation name="getTwitterSearch">

&lt;wsdl:input message="tns:getTwitterSearchRequest"/>

&lt;wsdl:output message="tns:getTwitterSearchResponse"/>

&lt;/wsdl:operation>

< / WSDL: portType >

< nome associazione = "twitterSearchServiceBinding"

type="tns:twitterSearchServicePortType">

&lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

&lt;wsdl:operation name="getTwitterSearch">

&lt;soap:operation soapAction="urn:ageService/getTwitterSearch" style="document"/>

&lt;wsdl:input>

&lt;soap:body use="literal"/>

&lt;/wsdl:input>

&lt;wsdl:output>

&lt;soap:body use="literal"/>

&lt;/wsdl:output>

&lt;/wsdl:operation>

< / vincolante >

< nome WSDL: Service = "twitterSearchService" >

&lt;wsdl:port name="twitterSearchServicePort"

binding="tns:twitterSearchServiceBinding">

&lt;soap:address location="http://localhost/php/twitterSearchService.php"/>

&lt;/wsdl:port>

< / WSDL: Service >

< / wsdl:definitions >

2

Inserire il codice sotto all'interno il <? php tag per creare un secondo file e il nome "php/twitterSearchService.php." Si noti che il file WSDL ha fatto riferimento a questo nome di file:

ini_set ("soap.wsdl_cache_enabled", "0");

$server = nuovo SoapServer("twitterSearchService.wsdl");

$server -> addFunction("getTwitterSearch");

$server -> handle ();

3

Incollare il seguente appena sopra il codice che appena inserito nel file per creare una nuova funzione denominata "getTwitterSearch."

Function getTwitterSearch ($searchText, $lastTwitterId) {

?

}

Questa funzione è dotato di due parametri: "searchText" e "lastTwitterId", che saranno integrati in un URL per accedere all'API di ricerca di Twitter.

4

Inserire il codice completo sotto per attivare la funzione che appena creato:

Function getTwitterSearch ($searchText, $lastTwitterId) {

$searchUrl = "http://search.twitter.com/search.atom?q=". $searchText;

if(!Empty($lastTwitterId)) () {

$searchUrl = $searchUrl."&since_id=".$lastTwitterId;

}

$twitterAtom = file_get_contents($searchUrl);

ritorno $twitterAtom;

}

Questo codice ottiene il contenuto dall'URL dove vengono elaborati gli ingressi di Twitter e restituisce le informazioni al client Silverlight.

Consigli & Avvertenze

  • Imparare PHP attraverso i diversi tutorial disponibili online. < br / >< br / >. Chiedere il parere di utenti esperti PHP iscrivendosi e partecipando a forum di discussione.