$#@60;?
if (empty($VisitedBefore))
{
// 如果没有设定cookie,为cookie赋上当前时间值
// 函数中的最后一个参数声明了该cookie保存的时间
// 在这个例子中是1年
// time()函数返回自1970年1月1日以来的以秒数计的时间
SetCookie("VisitedBefore",time(), time()+(60*60*24*365));
}
else
{
// 欢迎浏览者再次光临
echo "Hello there, welcome back$#@60;BR$#@62;";
// 读取cookie并判断
if ( (time() - $VisitedBefore) $#@62;= "(60*60*24*7)" )
echo "Why did you take a week to come back. You should be here more
often!? ";
}
?$#@62;
13.3 煤?
我们简单来看看一些常用的函数。
数组
array - 生成数组
count - 数组元素个数
sort - 数组排序,另有其他几种排序函数可供使用
list - 列出数组元素
each - 返回下一个key/value对
current - 返回当前数组元素
next,prev - 传回当前数组元素前后指针
日期和时间
checkdate - 验证日期/时间格式
date - 生成日期/时间格式
time - 当前时间信息
strftime - 格式化日期/时间
$#@60;?
include("include/common.inc");
// 我们在这里再做一次用户验证
if(!isset($PHP_AUTH_USER))
{
Header("WWW-Authenticate: Basic realm=\"$MySiteName\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Sorry, you are not authorized to upload files\n";
exit;
}
else
{
if ( !($PHP_AUTH_USER==$MyName && $PHP_AUTH_PW==$MyPassword )
)
{
// 如果是错误的用户名称/密码对,强制再次认证
Header("WWW-Authenticate: Basic realm=\"My Realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo "ERROR : $PHP_AUTH_USER/$PHP_AUTH_PW is invalid.$#@60;P$#@62;";
exit;
}
}
if ( $cancelit )
{
// 当浏览者按下"取消"按钮则转向首页面
header ( "Location: front_2.php3" );
exit;
}
function do_upload () {
global $userfile, $userfile_size, $userfile_name, $userfile_type;
global $local_file, $error_msg;
global $HTTP_REFERER;
if ( $userfile == "none" ) {
$error_msg = "You did not specify a file for uploading.";
return;
}
if ( $userfile_size $#@62; 2000000 )
{
$error_msg = "Sorry, your file is too large.";
return;
}
// Wherever you have write permission below...
$upload_dir = "photos";
$local_file = "$upload_dir/$userfile_name";
if ( file_exists ( $local_file ) ) {
$error_msg = "Sorry, a file with that name already exists";
return;
};
// 你还可以由此检查文件名称/类型对以确定是何种文件:gif,jpg,mp3…
rename($userfile, $local_file);
echo "The file is uploaded$#@60;BR$#@62;\n";
echo "$#@60;A HREF=\"$HTTP_REFERER\"$#@62;Go Back$#@60;/A$#@62;$#@60;BR$#@62;\n";
}
$title = "Upload File";
include("include/header.inc");
if (empty($userfile) || $userfile=="none")
{
// 输出以下表单
?$#@62;
$#@60;FORM ACTION="$#@60;? echo "$PHP_SELF"; ?$#@62;" ENCTYPE="multipart/form-data"
METHOD=POST$#@62;
$#@60;INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="2000000"$#@62;
$#@60;INPUT TYPE="FILE" NAME="userfile" SIZE="24"
MAXLENGTH="80"$#@62;
$#@60;BR$#@62;$#@60;BR$#@62;
$#@60;INPUT TYPE="SUBMIT" VALUE="Upload File!" NAME="sendit"$#@62;
$#@60;INPUT TYPE="SUBMIT" VALUE="Cancel" NAME="cancelit"$#@62;$#@60;BR$#@62;
$#@60;/FORM$#@62;
$#@60;I$#@62;$#@60;FONT SIZE="2"$#@62;(You may notice a slight delay
while we upload your file.)$#@60;/FONT$#@62;$#@60;/I$#@62;
$#@60;?
} else {
if ( $error_msg ) { echo "$#@60;B$#@62;$error_msg$#@60;/B$#@62;$#@60;BR$#@62;$#@60;BR$#@62;";
}
if ( $sendit ) {
do_upload ();
}
}
include("include/footer.inc");
?$#@62;
照片图库
$#@60;?
include("include/common.inc");
$title = "Gallery";
include("include/header.inc");
?$#@62;
$#@60;P$#@62;
Here are some of our family photos. This PHP script can really
be made better, by splitting into multiple pages.
$#@60;/P$#@62;
$#@60;?
$d = dir("photos");
while($entry = $d-$#@62;read())
{
if (is_file("photos/$entry"))
echo "$#@60;IMG SRC=\"photos/$entry\"$#@62;\n";
}
$d-$#@62;close();
?$#@62;
$#@60;?
include("include/footer.inc");
?$#@62;