php 访问控制
// An array of allowed users and their passwords
$users = array(
'harryf' => 'secret',
'tom' => 'mypwd'
);
// If there's no Authentication header, exit
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="PHP Secured"');
exit('This page requires authentication');
}
// If the user name doesn't exist, exit
if (!isset($users[$_SERVER['PHP_AUTH_USER']])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="PHP Secured"');
exit('Unauthorized!');
}
// Is the password doesn't match the username, exit
if ($users[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])
{
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="PHP Secured"');
exit('Unauthorized!');
}
echo 'You\'re in!';
?>
相关文档:
问题描述:一个连接远程数据库的PHP脚本testdb.php,在浏览器中运行:http://localhost/testdb.php,出现错误:Can't connect to MySQL server on '10.60.56.220' (13),但是在本地用php命令行运行:php testdb.php,却正常地连上了数据库并读出了其中的数据。
应用程序环境:本地IP:10.60.56.90,本地电脑上安装Apache 2 ......
class DB
{
private $link;
function connectDB($dbhost, $dbuser, $dbpw, $dbname="", $pconnect = 1)
{
if($pconnect)
{
if(!$this->link = mysql_pconnect($dbhost, $dbuser, ......
这种问题我想大家可能都遇到过,网友提供的解决方法也很多。我也只是结合自己系统的需求并结合网友的解决方案来总结的一种方法
用来作为解决php以root权限执行一些普通用户不能执行的命令或应用的参考。
其实php里的popen()函数是可以解决这个问题的,但是由于某些版本的linux(如我使用的Centos 5)对系统安全的考虑,
使 ......
1.方法一:
$dir="D:";
static $dir_list =0;
static $file_list =0;
function listfile($dir){
global $dir_list,$file_list;
$d = dir($dir);
while ( $entry = $d->read()) {
$tem_curnt=$dir."/".$entry;
if($entry=="." || $entry=="..") continue;
if ( is_dir( $tem_curnt)) {
......