php – 服务器端的CURL HTTP身份验证

栏目: PHP · 发布时间: 7年前

内容简介:Zend Framework具有用于处理HTTP身份验证的现成组件.结帐示例>

我正在使用Zend构建一个Web服务,我必须在发送回应之前验证用户.用户将使用curl发送请求到服务器页面,以curl_setopt($curl,CURLOPT_USERPWD,’key:pass’)的形式传递其凭据;

Iam使用Zend框架,所以服务器端页面如下表示:

http://www.example.com/app_name/public/controller/action/parameter

以下是用户请求的总代码(client.php):

<?php
$curl = curl_init('http://www.example.com/app/public/user/add/1');

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);                         
curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);                    
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);                          
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);                           
curl_setopt($curl, CURLOPT_USERAGENT, 'Sample Code');

$response = curl_exec($curl);                                          
$resultStatus = curl_getinfo($curl);                                   

if($resultStatus['http_code'] == 200) {
    echo $response;
} else {
    echo 'Call Failed '.print_r($resultStatus);                         
}

?>

现在我想要的是,我必须能够在服务器端检索用户名和密码(在我的zend控制器中),以便我可以验证来自数据库的用户凭据并相应地发送响应.那么我如何在另一个页面上进行身份验证?

Zend Framework具有用于处理HTTP身份验证的现成组件.

结帐示例

> http://framework.zend.com/manual/en/zend.auth.adapter.http.html

如果你不想使用它,你仍然可以按照“老派”的方式进行

> http://php.net/manual/en/features.http-auth.php

并手动检查$_SERVER [‘PHP_AUTH_USER’]和$_SERVER [‘PHP_AUTH_PW’]

http://stackoverflow.com/questions/4957002/curl-http-authentication-at-server-side


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Operations

Web Operations

John Allspaw、Jesse Robbins / O'Reilly Media / 2010-6-28 / USD 39.99

A web application involves many specialists, but it takes people in web ops to ensure that everything works together throughout an application's lifetime. It's the expertise you need when your start-u......一起来看看 《Web Operations》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具