Está en la página 1de 5

Web services

What is a Web Service? A "web service" is a network accessible interface to application functionality built using XML and usually HTTP. Three forms of Web Services o SOAP o XML-RPC o REST SOAP

Formerly known as Simple Object Access Protocol. Uses XML, but you never need to touch it. Which is good, because SOAP is messy to look at? You just call functions and manipulate arrays. (Unless you want to.) A few PHP implementations: PEAR::SOAP, PHP-SOAP, NuSOAP (Dirty little secret: Nobody uses SOAP.) SOAP is the most complicated and has interoperability problems but large vendors such as Microsoft,and IBM have thrown support behind it. XML Remote Procedure Call Similar to SOAP, but less complex Which is its biggest advantage And its biggest disadvantage But it is often "good enough" But, SOAP has better buzzword compliance XML-RPC offers a nice blend of power and simplicity but lacks big- vendor support.

XML-RPC REST

Representational State Transfer (Roy Fielding)

Make URI request using existing HTTP methods: GET / POST / PUT / DELETE. Data returned as XML, and you do need to touch it. Which is good, because it's not complicated. Many ways to parse XML: SAX / DOM / XSLT / SimpleXML\ REST is the most lightweight and easy to use but offers the least functionality

REST Vs SOAP Both REST (Representational states transfer) and SOAP is widely adopted techniques for building distributed systems. REST is an architectural style

for implementing systems on top of HTTP infrastructure. A large number of Specifications has been developed on top of SOAP and there are large number of SOAP stacks both open source and proprietary out there implementing large part of this WS* stack. Both these d techniques have their advantages and drawbacks. Here are few of the advantages and disadvantages of each paradigm. REST Advantages Based on few simple principles which are already in wide adoption on the Web itself Can be implemented very quickly. Ideal for providing simple API's to the users. (Eq Whether Services, Flicker, Yahoo REST services ) Amount of learning required to get started is minimum in comparison to SOAP Has a very large following amount the scripting community

Disadvantages

If the system is a very large one, then designing based on REST could
SOAP become a very complex task. Implementing Security on a REST system is one major issues. Although HTTPS, and HTTP Authentication can be used, they only provide transport level security.

Advantages Well designed mature technology Has been widely adopted in industry Large number of SOAP stacks available to choose from. Has support for Both Transport level and message level security which is a big advantage over REST. Supports multiple protocol bindings ( Not just HTTP) Ideal for implementing complex enterprise systems since the SOAP Stacks cater for security, reliability, transactions ect.

Disadvantages Complex in comparison to REST Big learning curve required Difficult to debug a complex system One great thing about using WSF/PHP is that it can support Both of these techniques simultaneously. However, if you are building a complex system which requires security, I would always recommend the use of SOAP.

This forms the first reason why we use Web Services. To restate the reason, - Web Services operate on a service-based model architecture. This the most compelling reason why we use Web Services.

The above diagram is the representation of a service based model. In this model, the web service resides on the web server. A client computer can request and consume this web service and terminate the service as and when desired. The name "service" originates from this model of functioning of the program. The client program needs to be provided with only the url of the web service.
The second reason for using is that Web Services allow us to communicate among all different entities without affecting their existence. This forms the third reason for using a web service is that it is written separately from the application logic. The fourth reason why we use Web Service is that they improve the information flow between applications. The fifth reason why we use Web Service is that, web services use text based protocol that all applications can understand. The sixth reason why we use Web Service is that, web services reduce licensing costs. The seventh reason for using Web services is that they do not rely on special protocols. Web services communicate using WWW(World wide web). They rely on standard Internet protocols HTTP and SOAP which are present in every system.

Send Mail using PHP


PHP allows you to send e-mails directly from a script. The PHP mail() Function The PHP mail() function is used to send emails from inside a script. Syntax mail(to,subject,message,headers,parameters) Parameter to subject message Description Required. Specifies the receiver / receivers of the email Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n)

headers

parameters

Optional. Specifies an additional parameter to the sendmail program Note: For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file. Read more in our PHP Mail reference.

PHP Simple E-Mail The simplest way to send an email with PHP is to send a text email. In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail: <?php $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>

PHP Mail Form With PHP, you can create a feedback-form on your website. The example below sends a text message to a specified e-mail address: <html> <body> <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html> This is how the example above works: First, check if the email input field is filled out If it is not set (like when the page is first visited); output the HTML form If it is set (after the form is filled out); send the email from the form When submit is pressed after the form is filled out, the page reloads, sees that the email input is set, and sends the email

Note: This is the simplest way to send e-mail, but it is not secure. In the next chapter of this tutorial you can read more about vulnerabilities in email scripts, and how to validate user input to make it more secure.

También podría gustarte