Phprpc for PHP Login
I've always wanted to look at what Web service is like under PHP. I finally got the time today. On the Internet to find the next PHPRPC Web service under PHP closed good, but also support other versions of the. Just mention it here.
Phprpc for PHP small application, interested can go to the official website to learn about the other version
Official website: http://www.phprpc.org/zh_CN/
First of all, simply say how to build it, download Phprpc_3.0.1_php.zip after decompression, will come out of these files
Dhparams//Folder Pecl//Folder Bigint.phpcompat.phpphprpc_date.phpdhparams.phpphprpc_server.phpphprpc_ client.phpxxtea.php
The following files belong to the public file, whether it is the server, or the client, need the
bigint.phpcompat.phpphprpc_date.phpxxtea.php
The following are the files required by the server
dhparamsdhparams.phpphprpc_server.phpbigint.phpcompat.phpphprpc_date.phpxxtea.php
The following are required by the client
phprpc_client.phpbigint.phpcompat.phpphprpc_date.phpxxtea.php
First build two folders in www directory
WebService
WebClient
Put the server files in the WebService.
Put the client's files in the WebClient.
Then create a new test.php file in the WebService.
The code is as follows
Include (' phprpc_server.php '), function IsLogin ($u, $p) {$con = mysql_connect (' localhost ', ' root ', ' 123 ') or Die (' Database connection failed '); mysql_select_db (' newspublish '); mysql_query (' SET NAMES utf8 '); $p = MD5 ($p); $sql = "SELECT * from T_user where ' u Sername ' = ' $u ' and ' password ' = ' $p ' ";//file_put_contents (' Log.txt ', $sql); $result = mysql_query ($sql); $n = Mysql_num_ Rows ($result), if ($n > 0) { return true;} else{ return false;}} function login ($u, $p) {if (IsLogin ($u, $p)) {return true;} Else{return false;}} The above code, I will not say, understand PHP, those are the basic $server = new Phprpc_server (); $server->add (' login ');//Add a method that allows remote access $server-> Setdebugmode (TRUE);//Open debug mode, but this I do not know how to use, research out the words will update the $server->start ();//Start
Build a client.php file in the WebClient.
Then look at the client code
Login (' LXX ', ' test ') {echo "Login success!";} Else{echo "Login wrong!"; >
And then access the http://localhost/webclient/client.php in the Address bar.
Look at the effect.
Isn't it simple! Here are just a few simple validations, for data reading, writing, these have not yet been studied,
Have the result, will be the first time to update, like, can pay attention to ha.
Also, it is necessary to note that if the results are different from what they want, and without any hint, go to the service side to find the wrong bar, although the debug mode is turned on, but do not know how to use, some code line has errors, the client does not prompt!