易截截图软件、单文件、免安装、纯绿色、仅160KB

php 访问控制

 <?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实现替换UTF

 批量去除BOM的程序
function
 replace_utf8bom(
$str
)  
{  
    $charset
[1] = 
substr
(
$str
,0,1);  
    $charset
[2] = 
substr
(
$str
,1,1);  
    $ch ......

[转载]PHP 计算时间差

我们常常在网站上看到某篇文章发表于“3天前”,“5个月前”,“4年前”。下面这个函数就提供了计算这个时间差的功能。
<?php
/**
* 时间差计算
*
* @param Timestamp $time
* @return String Time Elapsed
* @author Shelley Shyan
* @copyright http://phparch.cn (Professiona ......

php遍历所有文件及文件夹的方法

 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)) {
......

用PHP如何判断一个文件的编码?

 整理自:http://bbs.phpchina.com/viewthread.php?tid=18006
文件a.txt,用PHP如何判断它的编码是GBK还是UTF-8呢?
1,重新认识一下此问题,当时版主回复的时候我就觉得mb函数里一定有这样的功能,但今日研究了mb库,并没有这样的功能。用mb_detect_encoding总是不准确。
echo mb_detect_encoding(file_get_conten ......

PHP和Javascript的JSON交互(处理一个二维数组)

 
PHP的JSON类库我使用的是Services_JSON
,没什么特别的优点,也没什么明显的缺点,对付用足矣。
建立文件data.php

<?php
include(
"JSON.php"
);
$data
= array(
    
array(
'name'
=>
mb_convert_encoding
(
'老王'
,
'UTF-8'
,
'GBK'
), ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号