Home php教程 php手册 使用PHPRPC实现Ajax安全登录第1/2页

使用PHPRPC实现Ajax安全登录第1/2页

Jun 13, 2016 pm 12:04 PM
ajax different and use Safety accomplish yes frame Log in of

PHPRPC 与其它 ajax 框架不同,PHPRPC 遵循的是“只做一件事,并把它做好”的原则。它只负责数据传输,并且将传输做到最好!它将你以前用传统的 ajax 方式做不到或者很难做到的事情变得轻而易举!
相信好多人选择 PHPRPC 的一个主要原因就是它能够让你开发 ajax 应用变得更加容易!尽管 PHPRPC 的强大之处不仅限于此,但我不得不承认,这确实是 PHPRPC 的一大亮点!
所以,我们的第一站,就来看看如何用 PHPRPC 3.0 来编写 ajax 应用吧。

下 面我们举一个最简单的例子(甚至可以算是无聊的例子 :mrgreen: )来说明如何使用 PHPRPC 3.0 编写 ajax 应用。这个例子很好的说明了上面所提到的 MVC 模式如何具体的工作。这里我们先以 PHP 为服务器端的情况为例来说明。我们的第一个例子很简单,客户端输入一段字符串,然后服务器端计算出它的 SHA1 值。

复制代码 代码如下:


require_once("../php/phprpc_server.php");
$server = new PHPRPC_Server();
$server->add("sha1");
$server->start();
?>


只有这么简单的 4 行代码,就把 PHP 内置的 sha1 函数发布了。现在,客户端可以直接使用这个函数了。

复制代码 代码如下:






计算 SHA1









这个例子非常简单,并且跟 PHPRPC 有关的只有两条语句,一条是:

复制代码 代码如下:


var rpc = new PHPRPC_Client('sha1.php', ['sha1']);


这条语句用来创建一个 PHPRPC_Client 对象,第一个参数是服务器地址,这里可以用相对路径,也可以用绝对路径。
而且这个路径可以跨域!因此你可以做跨域的应用!
第二个参数是你需要使用的服务器端的函数名列表,所以,虽然我们这里只有一个函数,也要写成数组的形式。这样我们就有了一个可以调用服务器端方法的客户端对象了。
那该如何调用呢?我们来看第二条关于 PHPRPC 的语句:

复制代码 代码如下:


rpc.sha1(input, showResult);


这条语句相当简单,你会发现我们直接使用了服务器端发布的函数名作为 rpc 对象的一个方法来调用。它的第一个参数就是 sha1 函数的参数值。第二个参数是个函数,这个是回调函数,也就是说,当服务器端方法执行完之后就会自动调用这个函数来完成结果的处理。它是在前面定义的,你会 发现它有一个参数 result,这个参数就是我们的远程过程 sha1 的返回值,它是通过回调函数的这个参数传入的。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

PHP vs. Ajax: Solutions for creating dynamically loaded content PHP vs. Ajax: Solutions for creating dynamically loaded content Jun 06, 2024 pm 01:12 PM

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.

What is Bitget Launchpool? How to use Bitget Launchpool? What is Bitget Launchpool? How to use Bitget Launchpool? Jun 07, 2024 pm 12:06 PM

BitgetLaunchpool is a dynamic platform designed for all cryptocurrency enthusiasts. BitgetLaunchpool stands out with its unique offering. Here, you can stake your tokens to unlock more rewards, including airdrops, high returns, and a generous prize pool exclusive to early participants. What is BitgetLaunchpool? BitgetLaunchpool is a cryptocurrency platform where tokens can be staked and earned with user-friendly terms and conditions. By investing BGB or other tokens in Launchpool, users have the opportunity to receive free airdrops, earnings and participate in generous bonus pools. The income from pledged assets is calculated within T+1 hours, and the rewards are based on

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

Which wallet is safer for SHIB coins? (Must read for newbies) Which wallet is safer for SHIB coins? (Must read for newbies) Jun 05, 2024 pm 01:30 PM

SHIB coin is no longer unfamiliar to investors. It is a conceptual token of the same type as Dogecoin. With the development of the market, SHIB’s current market value has ranked 12th. It can be seen that the SHIB market is hot and attracts countless investments. investors participate in investment. In the past, there have been frequent transactions and wallet security incidents in the market. Many investors have been worried about the storage problem of SHIB. They wonder which wallet is safer for SHIB coins at the moment? According to market data analysis, the relatively safe wallets are mainly OKXWeb3Wallet, imToken, and MetaMask wallets, which will be relatively safe. Next, the editor will talk about them in detail. Which wallet is safer for SHIB coins? At present, SHIB coins are placed on OKXWe

How to choose the best golang framework for different application scenarios How to choose the best golang framework for different application scenarios Jun 05, 2024 pm 04:05 PM

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

Guide to secure coding in PHP frameworks Guide to secure coding in PHP frameworks Jun 05, 2024 pm 02:32 PM

Prevent security vulnerabilities in the PHP framework: ① Use prepared statements to avoid SQL injection. ②Escape HTML content to prevent XSS attacks. ③ Filter user input to verify correctness. ④ Disable dangerous functions such as eval() and system(). ⑤Use safe_require() or require_once() for safe file inclusion.

See all articles