初学PHP的18个基础实例 |
|
来源:互联网 作者:本站整理 发布时间:2007-12-29 |
|
|
十三:限制访问某个页面
以下为引用的内容: // choose a user name and password between the " " symbol //=========================== $admin_user_name="admin"; // your admin username $admin_password="pass"; // your password $site_com="webjx.com"; // your website name WITHOUT http:// and www $login="你已经登陆"; // succesful message when user are logged in ( NOT NECESSARY ) //===========================
// DO NOT EDIT NOTHING BELOW!
if ((!isset($PHP_AUTH_USER)) || (!isset($PHP_AUTH_PW))) {
/* No values: send headers causing dialog box to appear */ php程序员站
header('WWW-Authenticate: Basic realm="$site_com"');
header('HTTP/1.0 401 Unauthorized');
echo '<h1>访问的页面被限制.</h1>请检查你的用户名或密码是否正确,正常登陆本站才能查看 本站的内容'; exit;
} else if ((isset($PHP_AUTH_USER)) && (isset($PHP_AUTH_PW))){ /* Values contain some values, so check to see if they're correct */
if (($PHP_AUTH_USER != "$admin_user_name") || ($PHP_AUTH_PW != "$admin_password")) { /* If either the username entered is incorrect, or the password entered is incorrect, send the headers causing dialog box to appear */
header('WWW-Authenticate: Basic realm="$site_com"'); header('HTTP/1.0 401 Unauthorized'); echo '<h1>访问的页面被限制.</h1>请检查你的用户名或密码是否正确,正常登陆本站才能查看 本站的内容'; exit; } else if (($PHP_AUTH_USER == "$admin_user_name") || ($PHP_AUTH_PW == "$admin_password")) { echo "$login phperz.com "; } }
?> |
保存为log.php,把下列代码加到head页内,那么将会保护所有的页面。
<? require("log.php");?>
十四、制作一个自动转向:
以下为引用的内容: <?php
header("Refresh:0; url=http://webjx.com");
?> |
必须保存为php文件才可以。
十五。制作用户列表:
以下为引用的内容: phperz~com <? $customer[0] = 'phperz'; $customer[1] = 'web'; $customer[2] = 'mutou'; $customer[3] = 'chuxia'; $customer[4] = 'shenhua'; echo "第3个用户是: $customer[2]";
echo "所有的用户:";
$number = 5; $x = 0; while ($x < $number) { $customernumber = $x + 0; echo "Costumer Name $customernumber is $customer[$x] "; ++$x; } ?>
|
将会显示: The third customer is mutou
所有的用户:
Costumer Name 0 is webjx Costumer Name 1 is web Costumer Name 2 is mutou Costumer Name 3 is chuxia Costumer Name 4 is shenhua
另一种读取数组的方法:
以下为引用的内容: php程序员之家 <? echo "3 of my customer are: $customer[0], " . " $customer[1] and " . " $customer[2]. " . ""; ?> |
将会显示: 3 of my customer are: webjx, web and mutou.
十六.统计某个目录下文件的数量:
以下为引用的内容: <? echo("There is "); $dir = "/path/to/the/folder/in/your/computer "; $count = 0; $handle=opendir($dir); while (($file = readdir($handle))!== false){ if ($file != "." && $file != "..") { $count++; }} echo $count; phperz~com
echo(" Pages For You To Search In This Directory."); ?> |
十七.显示当前日期或最新更新的日期:
以下为引用的内容: <?php echo date("F d Y"); ?>
显示更新日期:
<?php echo "Last Modified: " . date ("m/d/y.", getlastmod());?> |
十八.重复一个字符多次的代码:
以下为引用的内容: phperz.com
<? echo str_repeat("-", 30); ?> |
php程序员之家
|
上一页12345下一页 |
[收藏此页] [打印本页] [返回顶部] |
|
|
|
|
|
|
|
|
|