Using PHPRPC to implement AJAX secure login 1th/2 page _php Tutorial

Source: Internet
Author: User
Tags sha1
Phprpc Unlike other Ajax frameworks, Phprpc follows the principle of "doing only one thing and doing it well". It is only responsible for data transmission, and will transmit to do the best! It makes it easy to do things that you've never done or are hard to do with traditional AJAX methods!
One of the main reasons to believe that many people choose PHPRPC is that it makes it easier for you to develop AJAX applications! Although the strength of PHPRPC is not limited to this, but I have to admit that this is indeed a big phprpc of the bright spot!
So, our first stop, let's see how to write Ajax applications with Phprpc 3.0来.

Let's take a simple example (even a boring example: Mrgreen:) to illustrate how to write AJAX applications using PHPRPC 3.0. This example is a good illustration of how the MVC pattern mentioned above works in detail. Here, let's take PHP as a server-side example to illustrate. Our first example is simple, the client enters a string, and the server calculates its SHA1 value.
Copy CodeThe code is as follows:
Require_once (".. /php/phprpc_server.php ");
$server = new Phprpc_server ();
$server->add ("SHA1");
$server->start ();
?>

With this simple 4-line code, the PHP built-in SHA1 function is released. Now, the client can use this function directly.
Copy CodeThe code is as follows:




<title>Calculate SHA1</title>









This example is very simple, and there are only two statements related to Phprpc, one is:
Copy CodeThe code is as follows:
var rpc = new Phprpc_client (' sha1.php ', [' SHA1 ']);

This statement is used to create a Phprpc_client object, the first parameter is the server address, where you can use a relative path, or you can use an absolute path.
And this path can cross the domain! So you can do cross-domain applications!
The second parameter is the list of server-side function names you need to use, so although we have only one function here, we have to write the form of an array. So we have a client object that can invoke the server-side method.
So how do you call it? Let's look at the second statement about PHPRPC:
Copy CodeThe code is as follows:
RPC.SHA1 (input, showresult);

This statement is fairly straightforward and you will find that we use the server-side published function name as a method of RPC object invocation. Its first parameter is the parameter value of the SHA1 function. The second parameter is a function, which is a callback function, that is, when the server-side method executes, it will automatically call this function to complete the processing of the results. It is defined earlier and you will find that it has a parameter of result, which is the return value of our remote procedure SHA1, which is passed in by this parameter of the callback function.

http://www.bkjia.com/PHPjc/324466.html www.bkjia.com true http://www.bkjia.com/PHPjc/324466.html techarticle Phprpc Unlike other Ajax frameworks, Phprpc follows the principle of "doing only one thing and doing it well". It is only responsible for data transmission, and will transmit to do the best! It's going to pass you by before ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.