$ _ SERVER ['PHP_AUTH_USER']空 [英] $_SERVER['PHP_AUTH_USER'] empty

查看:435
本文介绍了$ _ SERVER ['PHP_AUTH_USER']空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:问题不在于PHP,我用卷曲错了。更新的问题,显示问题,我与XHR拥有。

摘要:使用XHR无法获取用户名PHP:

  VAR XHR = Ti.Network.createHTTPClient();
xhr.timeout = 1000000;
xhr.open(GET,http://myapi.com/test,假的,用户,通行证);
xhr.send();

在我的PHP脚本,我试图与此访问的用户名:

 < PHP打印$ _ SERVER ['PHP_AUTH_USER']; ?>

不管是什么我尝试它总是空的。

有没有办法,我需要配置一些PHP设置?

更多信息:PHP 5.2.13版本,阿帕奇,MAMP


解决方案

 <脚本SRC =htt​​p://www.webtoolkit.info/djs/webtoolkit.base64.js >< / SCRIPT>
<脚本>
VAR XHR = Ti.Network.createHTTPClient();
xhr.timeout = 1000000;
xhr.onreadystatechange =功能(){
    如果(xhr.readyState = 4!)回报;
    警报('服务器说:'+ xhr.responseText);
};
xhr.open('GET','http://myapi.com/test',FALSE);
xhr.setRequestHeader('授权','基本'+ Base64.en code('用户名:通'));
xhr.send('');
< / SCRIPT>

(为礼貌起见,你应该下载webtoolkit.base64.js,并从自己的服务器为它服务。)

请记住,你不能做XHR跨域请求;你的JavaScript和PHP已经被来自同一个域提供服务。

EDIT: Problem isn't with PHP, I was using cURL wrong. Updated question to show problem I'm having with XHR.

Summary: Can't get username to PHP using XHR:

var xhr = Ti.Network.createHTTPClient();
xhr.timeout = 1000000;
xhr.open("GET","http://myapi.com/test", false, 'user', 'pass');
xhr.send();

And in my PHP script, I'm trying to access the username with this:

<?php print $_SERVER['PHP_AUTH_USER']; ?>

No matter what I try it's always empty.

Is there some PHP setting that I need to configure?

More info: PHP Version 5.2.13, Apache, MAMP

解决方案

<script src="http://www.webtoolkit.info/djs/webtoolkit.base64.js"></script>
<script>
var xhr = Ti.Network.createHTTPClient();
xhr.timeout = 1000000;
xhr.onreadystatechange = function() {
    if (xhr.readyState != 4) return;
    alert('Server said: '+xhr.responseText);
};
xhr.open('GET', 'http://myapi.com/test', false);
xhr.setRequestHeader('Authorization', 'Basic ' + Base64.encode('user:pass') );
xhr.send('');
</script>

(For the sake of courtesy, you should download webtoolkit.base64.js and serve it from your own server.)

Keep in mind that you can't do cross-domain requests with XHR; your JavaScript and PHP have to be served from the same domain.

这篇关于$ _ SERVER ['PHP_AUTH_USER']空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆