Using PHPRPC to implement Ajax secure login Page 1/2_PHP Tutorial
WBOYOriginal
2016-07-21 15:23:35904browse
PHPRPC is different from other ajax frameworks. PHPRPC follows the principle of "just do one thing and do it well". It is only responsible for data transmission and does the best possible job! It makes things that you couldn't do or were difficult to do using traditional ajax methods become a piece of cake! I believe one of the main reasons why many people choose PHPRPC is that it can make it easier for you to develop ajax applications! Although the power of PHPRPC is not limited to this, I have to admit that this is indeed a highlight of PHPRPC! So, our first stop is to see how to use PHPRPC 3.0 to write ajax applications.
Below we give the simplest example (even a boring example :mrgreen: ) to illustrate how to use PHPRPC 3.0 to write an ajax application. This example is a good example of how the MVC pattern mentioned above works. Here we first take the case where PHP is the server side as an example to illustrate. Our first example is simple, the client inputs a string, and the server calculates its SHA1 value.
Copy code The code is as follows:
require_once("../php/phprpc_server.php "); $server = new PHPRPC_Server(); $server->add("sha1"); $server->start(); ?>
With only such a simple 4 lines of code, PHP's built-in sha1 function is released. Now, clients can use this function directly.
Copy code The code is as follows:
Calculate SHA1< ;/title>
This example is very simple, and there are only two statements related to PHPRPC, one is:
Copy code The 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. You can use a relative path or an absolute path here. And this path can cross domains! So you can do cross-domain applications! The second parameter is a list of server-side function names you need to use, so even though we only have one function here, it must be written in the form of an array. Now we have a client object that can call server-side methods. How to call it? Let’s look at the second statement about PHPRPC:
Copy code The code is as follows:
rpc.sha1(input, showResult );
This statement is quite simple. You will find that we directly use the function name published by the server as a method of the rpc object to call. Its first parameter is the parameter value of the sha1 function. The second parameter is a function, which is a callback function. That is to say, when the server-side method is executed, this function will be automatically called to complete the result processing. It was defined earlier, and you will find that it has a parameter result, which is the return value of our remote process sha1, which is passed in through this parameter of the callback function.
http://www.bkjia.com/PHPjc/324466.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324466.htmlTechArticlePHPRPC is different from other ajax frameworks, PHPRPC follows the principle of "just do one thing and do it well" principle. It is only responsible for data transmission and will do the best possible job! It will transfer what you used to use...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn