我目前在我的php内部网站点遇到问题,我正在尝试使用' AUTH_USER'来动态地将用户统计数据加载到表格中用户名。
在服务器(IIS 8)上设置了Windows身份验证,当我运行以下命令时,登录用户显示正确。
<?php
$user = $_SERVER['AUTH_USER'];
echo "$user";
?>
当我尝试使用AUTH_USER动态填充时,表格根本不显示任何信息。
<script type="text/javascript" src="http://exampleserver/content/widgets/widgets.js"></script>
<script type="text/javascript">
var pcUsername = '<?= $_SERVER['AUTH_USER'] ?>';
var pcServerURL = 'http://exampleserver';
pcGetUserDetails();
</script>
<h3>Test Widget</h3>
<div id="customwidget">
<table style="border: solid 1px black;">
<tr>
<th>Username:</th>
<td id="userName"></td>
</tr>
<tr>
<th>Balance:</th>
<td id="userBalance"></td>
</tr>
<tr>
<th>Restricted:</th>
<td id="userRestricted"></td>
</tr>
<tr>
<th>Pages:</th>
<td id="userPages"></td>
</tr>
<tr>
<th>Jobs:</th>
<td id="userJobs"></td>
</tr>
<tr>
<th>CO2:</th>
<td id="userCO2"></td>
</tr>
<tr>
<th>Trees:</th>
<td id="userTrees"></td>
</tr>
<tr>
<th>Bulb Hours:</th>
<td id="userBulbHours"></td>
</tr>
<tr>
<th>Since Date:</th>
<td id="userSinceDate"></td>
</tr>
</table>
</div>
<script type="text/javascript">
document.getElementById('userName').innerHTML = pcUsername;
if (pcUserDetails.balanceFormatted != undefined) {
document.getElementById('userBalance').innerHTML = pcUserDetails.balanceFormatted;
document.getElementById('userRestricted').innerHTML = pcUserDetails.restricted;
document.getElementById('userPages').innerHTML = pcUserDetails.printStats.pages;
document.getElementById('userJobs').innerHTML = pcUserDetails.printStats.jobs;
document.getElementById('userCO2').innerHTML = pcUserDetails.environmentalImpact.gramsCO2Formatted;
document.getElementById('userTrees').innerHTML = pcUserDetails.environmentalImpact.treesFormatted;
document.getElementById('userBulbHours').innerHTML = pcUserDetails.environmentalImpact.bulbHoursFormatted;
document.getElementById('userSinceDate').innerHTML = pcUserDetails.printStats.sinceDateFormatted;
}
</script>
&#13;
我已经检查过,如果手动添加名称,表格会正确提取用户数据。例如
var pcUsername = 'testuser1';
正确填充&#39; testuser1&#39;的数据。我也尝试了$ _SERVER [&#39; PHP_AUTH_USER&#39;]但它不起作用。
非常感谢任何帮助。