当前位置: 编程技术>php
本页文章导读:
▪PHP实现用户认证及管理完全源码
-- begin auth.inc -- <?php $id = "xxxCOM"; if(!isset($PHP_AUTH_USER)) { Header("WWW-Authenticate: Basic realm="$id""); Header("HTTP/1.0 401 Unauthorized"); require('error.inc'); exit; } $name = $PHP_.........
▪一个可分页的基于文本的PHP留言板源码第1/2页
小弟初学PHP,编了一个留言板程序,自我感觉良好,故厚着脸皮放了上来,请各位大哥指正。源程序如下: <?php //文件名:guest.php //设定部分 $guestfile="guest";//纪录留言的文本文件 .........
▪随时给自己贴的图片加文字的php代码
<? Header( "Content-type: image/jpeg"); function makethumb($srcFile,$text,$size=12,$R=0,$G=0,$B=0) { if(!$text){ $text=''welcome to imbbs.cn''; $size=20; $R=255; } $data = GetImageSize($srcFile,&$info); switch ($dat.........
[1]PHP实现用户认证及管理完全源码
来源: 互联网 发布时间: 2013-11-30
-- begin auth.inc --
<?php
$id = "xxxCOM";
if(!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm="$id"");
Header("HTTP/1.0 401 Unauthorized");
require('error.inc');
exit;
}
$name = $PHP_AUTH_USER;
$pass = $PHP_AUTH_PW;
require("connect.inc");
$query = "select * from auth where username='$name' && realm='$id'";
$result = mysql_db_query("admin", $query);
if(mysql_num_rows($result) == 0) {
Header("WWW-Authenticate: Basic realm="$id"");
Header("HTTP/1.0 401 Unauthorized");
require('error.inc');
exit;
}
$active = mysql_result($result,0,"active");
if($active == 'no') {
?>
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL
<? echo $REQUEST_URI; ?>
was not found on this server.<P>
</BODY></HTML>
<?php
exit;
}
?>
-- end auth.inc --
-- begin connect.inc --
<?php mysql_connect("localhost", "user", ""); ?>
-- end connect.inc --
-- begin error.inc --
此文件存放错误信息及返回!
-- end error.inc --
-- 用户库结构(自己调整)--
CREATE TABLE auth (
id smallint(6) DEFAULT '0' NOT NULL auto_increment,
username varchar(16) DEFAULT '' NOT NULL,
lastname tinyblob,
firstname tinyblob,
password varchar(16),
realm varchar(16),
active char(3),
PRIMARY KEY (id),
UNIQUE id (id),
UNIQUE username (username)
);
-- 用户库结构结束--
-- 添加用户示例--
insert into auth (username, lastname, firstname, password, realm, active) values ('admin','my','love','password','xxxCOM','yes');
-- 结束--
--用户管理程序开始 usermanage.php --
<?php include("auth.inc"); ?>
<?php
if ($PHP_AUTH_USER != "admin") {
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
Header("HTTP/1.0 401 Unauthorized");
echo "Access Denied!n";
exit;
};
if ($PHP_AUTH_PW != "mypassword") {
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
Header("HTTP/1.0 401 Unauthorized");
echo "Access Denied!n";
exit;
};
if ($activate) {
include("connect.inc");
$query1 = "UPDATE auth SET active='yes' where id='$id'";
$result1 = mysql_db_query("admin", $query1);
if ($result1) {
echo "<font size="+1">n";
echo "$user activatedn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
} else {
echo "<font size="+1">n";
echo "Error: Unknown Errorn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
}
}
if ($deactivate) {
include("connect.inc");
$query2 = "UPDATE auth SET active='no' where id='$id'";
$result2 = mysql_db_query("admin", $query2);
if ($result2) {
echo "<font size="+1">n";
echo "$user deactivatedn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
} else {
echo "<font size="+1">n";
echo "Error: Unknown Errorn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
}
}
if ($delete) {
include("connect.inc");
$query3 = "delete from auth where id='$id'";
$result3 = mysql_db_query("admin", $query3);
if ($result3) {
echo "<font size="+1">n";
echo "$user 已删除!n";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
} else {
echo "<font size="+1">n";
echo "Error: Unknown Errorn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
}
}
echo "<html>n";
echo "<head>n";
echo "<title>用户管理</title>n";
echo "</head>n";
echo "<body>n";
echo "<form method="post" action="/blog_article/$PHP_SELF/index.html">\n";
echo "<table border="1">n";
echo "<tr><th><font size="+1">Username</font></th><th><font size="+1">Real Name</font></th><th><font size="+1">Activated</font></th></tr>n";
include("connect.inc");
$query = "SELECT * FROM auth";
$result = mysql_db_query("admin", $query);
if ($result) {
while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$username = $r["username"];
$lastname = $r["lastname"];
$firstname = $r["firstname"];
$activated = $r["active"];
if ($activated == "yes") {
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname, $firstname</font></td><td><font size="+1">$activated</font></td><td><a href="/blog_article/$PHP_SELF/deactivate/yes/amp;id/$id/amp;user/$username.html">Deactivate</a></td><td><a href="/blog_article/$PHP_SELF/delete/yes/amp;id/$id.html">Delete</a></td></tr>n";
} elseif ($activated == "no") {
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname, $firstname</font></td><td><font size="+1">$activated</font></td><td><a href="/blog_article/$PHP_SELF/activate/yes/amp;id/$id.html">Activate</a></td><td><a href="/blog_article/$PHP_SELF/delete/yes/amp;id/$id.html">Delete</a></td></tr>n";
}
}
}
mysql_free_result($result);
echo "</table>\n";
echo "</body>\n";
echo "</html>\n";
?>
-- usermanage.php 结束--
<?php
$id = "xxxCOM";
if(!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm="$id"");
Header("HTTP/1.0 401 Unauthorized");
require('error.inc');
exit;
}
$name = $PHP_AUTH_USER;
$pass = $PHP_AUTH_PW;
require("connect.inc");
$query = "select * from auth where username='$name' && realm='$id'";
$result = mysql_db_query("admin", $query);
if(mysql_num_rows($result) == 0) {
Header("WWW-Authenticate: Basic realm="$id"");
Header("HTTP/1.0 401 Unauthorized");
require('error.inc');
exit;
}
$active = mysql_result($result,0,"active");
if($active == 'no') {
?>
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL
<? echo $REQUEST_URI; ?>
was not found on this server.<P>
</BODY></HTML>
<?php
exit;
}
?>
-- end auth.inc --
-- begin connect.inc --
<?php mysql_connect("localhost", "user", ""); ?>
-- end connect.inc --
-- begin error.inc --
此文件存放错误信息及返回!
-- end error.inc --
-- 用户库结构(自己调整)--
CREATE TABLE auth (
id smallint(6) DEFAULT '0' NOT NULL auto_increment,
username varchar(16) DEFAULT '' NOT NULL,
lastname tinyblob,
firstname tinyblob,
password varchar(16),
realm varchar(16),
active char(3),
PRIMARY KEY (id),
UNIQUE id (id),
UNIQUE username (username)
);
-- 用户库结构结束--
-- 添加用户示例--
insert into auth (username, lastname, firstname, password, realm, active) values ('admin','my','love','password','xxxCOM','yes');
-- 结束--
--用户管理程序开始 usermanage.php --
<?php include("auth.inc"); ?>
<?php
if ($PHP_AUTH_USER != "admin") {
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
Header("HTTP/1.0 401 Unauthorized");
echo "Access Denied!n";
exit;
};
if ($PHP_AUTH_PW != "mypassword") {
Header("WWW-Authenticate: Basic realm="xxxCOM 客户认证"");
Header("HTTP/1.0 401 Unauthorized");
echo "Access Denied!n";
exit;
};
if ($activate) {
include("connect.inc");
$query1 = "UPDATE auth SET active='yes' where id='$id'";
$result1 = mysql_db_query("admin", $query1);
if ($result1) {
echo "<font size="+1">n";
echo "$user activatedn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
} else {
echo "<font size="+1">n";
echo "Error: Unknown Errorn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
}
}
if ($deactivate) {
include("connect.inc");
$query2 = "UPDATE auth SET active='no' where id='$id'";
$result2 = mysql_db_query("admin", $query2);
if ($result2) {
echo "<font size="+1">n";
echo "$user deactivatedn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
} else {
echo "<font size="+1">n";
echo "Error: Unknown Errorn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
}
}
if ($delete) {
include("connect.inc");
$query3 = "delete from auth where id='$id'";
$result3 = mysql_db_query("admin", $query3);
if ($result3) {
echo "<font size="+1">n";
echo "$user 已删除!n";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
} else {
echo "<font size="+1">n";
echo "Error: Unknown Errorn";
echo "<br>n<a href="/blog_article/$PHP_SELF/index.html">返回</a>\n";
echo "</font>n";
exit;
}
}
echo "<html>n";
echo "<head>n";
echo "<title>用户管理</title>n";
echo "</head>n";
echo "<body>n";
echo "<form method="post" action="/blog_article/$PHP_SELF/index.html">\n";
echo "<table border="1">n";
echo "<tr><th><font size="+1">Username</font></th><th><font size="+1">Real Name</font></th><th><font size="+1">Activated</font></th></tr>n";
include("connect.inc");
$query = "SELECT * FROM auth";
$result = mysql_db_query("admin", $query);
if ($result) {
while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$username = $r["username"];
$lastname = $r["lastname"];
$firstname = $r["firstname"];
$activated = $r["active"];
if ($activated == "yes") {
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname, $firstname</font></td><td><font size="+1">$activated</font></td><td><a href="/blog_article/$PHP_SELF/deactivate/yes/amp;id/$id/amp;user/$username.html">Deactivate</a></td><td><a href="/blog_article/$PHP_SELF/delete/yes/amp;id/$id.html">Delete</a></td></tr>n";
} elseif ($activated == "no") {
echo "<tr><td><font size="+1">$username</font></td><td><font size="+1">$lastname, $firstname</font></td><td><font size="+1">$activated</font></td><td><a href="/blog_article/$PHP_SELF/activate/yes/amp;id/$id.html">Activate</a></td><td><a href="/blog_article/$PHP_SELF/delete/yes/amp;id/$id.html">Delete</a></td></tr>n";
}
}
}
mysql_free_result($result);
echo "</table>\n";
echo "</body>\n";
echo "</html>\n";
?>
-- usermanage.php 结束--
[2]一个可分页的基于文本的PHP留言板源码第1/2页
来源: 互联网 发布时间: 2013-11-30
小弟初学PHP,编了一个留言板程序,自我感觉良好,故厚着脸皮放了上来,请各位大哥指正。源程序如下:
<?php
//文件名:guest.php
//设定部分
$guestfile="guest";//纪录留言的文本文件
$home="index.html";//返回的主页
$imagedir="image"; //图像文件的目录
$backimage=$imagedir."/bk.gif";//背景图像
$backcolor="#ceffff";//背景颜色,在$backimage=""时起作用
?>
<html>
<head>
<?php
if($QUERY_STRING!="") {
$page = $QUERY_STRING;
} else {
$page = 1;
}
if($mode=="add"){
$name=htmlspecialchars(trim($name));
$title=htmlspecialchars(trim($title));
$data=nl2br(htmlspecialchars($data));
$data=str_replace("r","",$data);
$data=str_replace("x0A","",$data);
$data=str_replace(" "," ",$data);
if($data=="") $data=" ";
$e_mail=trim($e_mail);
if($e_mail=="") $e_mail=0;
$url=trim($url);
if($url=="http://" || $url=="") $url=0;
$time=date("Y")."年".date("m")."月".date("d")."日[".date("H").":".date("i").":".date("s")."]";
if($name=="" || $title==""){
echo "<script Language="JavaScript">n";
echo " alert("请至少输入姓名与留言标题。");n";
echo "history.back();";
echo "</script></head></html>n";
exit;
}
$adddata=$name."t".$e_mail."t".$url."t".$title."t".$data."t".$icon."t".$time."n";
if(file_exists($guestfile)){
$filebuffer=file($guestfile);
if(sizeof($filebuffer)>100){
for($i=0;$i<100;$i++)
$newbuffer[i]=$filebuffer[i];
}
else{
$newbuffer=$filebuffer;
}
$fp=fopen($guestfile,"w");
fputs($fp,$adddata);
fclose($fp);
$buffer=implode("",$newbuffer);
$fp=fopen($guestfile,"a");
fputs($fp,$buffer);
fclose($fp);
}
else{
$fp=fopen($guestfile,"w");
fwrite($fp,$adddata);
fclose($fp);
}
}
?>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>留言板</title>
<style>
a{text-decoration:none; font-size:9pt; color:blue}
a:visited {text-decoration:none; color:009999}
a:hover {color:red; text-decoration:underline}
td{font-size:9pt;line-height:14pt}
P{font-size:9pt}
</style>
</head>
<?php
if($backimage!="" && file_exists($backimage)){
echo "<body background="".$backimage."" bgproperties="fixed">n";
}
else{
echo "<body bgcolor="".$backcolor."">n";
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#9999FF">
<td height="28">
<div align="center"><b>供电9901网上空间留言板</b></div>
</td>
</tr>
<tr><td><div align="right"><a href="/blog_article/</ echo $home; /gt;.html">[返回首页]</a></div></td></tr>
</table>
<font size="2">
<form method="post" action="/blog_article/guest.html">
<input type="hidden" name="mode" value="add">
<p>姓名:
<input type="text" name="name" size="20">
<br>
E_Mail:
<input type="text" name="e_mail" size="20">
<br>
主页:
<input type="text" name="url" value="http://" size="30">
<br>
留言标题:
<input type="text" name="title" size="50">
<br>
留言内容:(不支持HTML)<br>
<textarea name="data" rows="5" cols="60"></textarea>
<div id="Layer1" >
<p>表情:</p>
<p>
<input type="radio" name="icon" value="1">
<img src="/blog_article/</ echo $imagedir..html"/1.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="2">
<img src="/blog_article/</ echo $imagedir..html"/2.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="3">
<img src="/blog_article/</ echo $imagedir..html"/3.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="4" checked>
<img src="/blog_article/</ echo $imagedir..html"/4.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="5">
<img src="/blog_article/</ echo $imagedir..html"/5.gif"; ?>" width="15" height="15">
<?php
//文件名:guest.php
//设定部分
$guestfile="guest";//纪录留言的文本文件
$home="index.html";//返回的主页
$imagedir="image"; //图像文件的目录
$backimage=$imagedir."/bk.gif";//背景图像
$backcolor="#ceffff";//背景颜色,在$backimage=""时起作用
?>
<html>
<head>
<?php
if($QUERY_STRING!="") {
$page = $QUERY_STRING;
} else {
$page = 1;
}
if($mode=="add"){
$name=htmlspecialchars(trim($name));
$title=htmlspecialchars(trim($title));
$data=nl2br(htmlspecialchars($data));
$data=str_replace("r","",$data);
$data=str_replace("x0A","",$data);
$data=str_replace(" "," ",$data);
if($data=="") $data=" ";
$e_mail=trim($e_mail);
if($e_mail=="") $e_mail=0;
$url=trim($url);
if($url=="http://" || $url=="") $url=0;
$time=date("Y")."年".date("m")."月".date("d")."日[".date("H").":".date("i").":".date("s")."]";
if($name=="" || $title==""){
echo "<script Language="JavaScript">n";
echo " alert("请至少输入姓名与留言标题。");n";
echo "history.back();";
echo "</script></head></html>n";
exit;
}
$adddata=$name."t".$e_mail."t".$url."t".$title."t".$data."t".$icon."t".$time."n";
if(file_exists($guestfile)){
$filebuffer=file($guestfile);
if(sizeof($filebuffer)>100){
for($i=0;$i<100;$i++)
$newbuffer[i]=$filebuffer[i];
}
else{
$newbuffer=$filebuffer;
}
$fp=fopen($guestfile,"w");
fputs($fp,$adddata);
fclose($fp);
$buffer=implode("",$newbuffer);
$fp=fopen($guestfile,"a");
fputs($fp,$buffer);
fclose($fp);
}
else{
$fp=fopen($guestfile,"w");
fwrite($fp,$adddata);
fclose($fp);
}
}
?>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>留言板</title>
<style>
a{text-decoration:none; font-size:9pt; color:blue}
a:visited {text-decoration:none; color:009999}
a:hover {color:red; text-decoration:underline}
td{font-size:9pt;line-height:14pt}
P{font-size:9pt}
</style>
</head>
<?php
if($backimage!="" && file_exists($backimage)){
echo "<body background="".$backimage."" bgproperties="fixed">n";
}
else{
echo "<body bgcolor="".$backcolor."">n";
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#9999FF">
<td height="28">
<div align="center"><b>供电9901网上空间留言板</b></div>
</td>
</tr>
<tr><td><div align="right"><a href="/blog_article/</ echo $home; /gt;.html">[返回首页]</a></div></td></tr>
</table>
<font size="2">
<form method="post" action="/blog_article/guest.html">
<input type="hidden" name="mode" value="add">
<p>姓名:
<input type="text" name="name" size="20">
<br>
E_Mail:
<input type="text" name="e_mail" size="20">
<br>
主页:
<input type="text" name="url" value="http://" size="30">
<br>
留言标题:
<input type="text" name="title" size="50">
<br>
留言内容:(不支持HTML)<br>
<textarea name="data" rows="5" cols="60"></textarea>
<div id="Layer1" >
<p>表情:</p>
<p>
<input type="radio" name="icon" value="1">
<img src="/blog_article/</ echo $imagedir..html"/1.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="2">
<img src="/blog_article/</ echo $imagedir..html"/2.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="3">
<img src="/blog_article/</ echo $imagedir..html"/3.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="4" checked>
<img src="/blog_article/</ echo $imagedir..html"/4.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="5">
<img src="/blog_article/</ echo $imagedir..html"/5.gif"; ?>" width="15" height="15">
[3]随时给自己贴的图片加文字的php代码
来源: 互联网 发布时间: 2013-11-30
<?
Header( "Content-type: image/jpeg");
function makethumb($srcFile,$text,$size=12,$R=0,$G=0,$B=0) {
if(!$text){
$text=''welcome to imbbs.cn'';
$size=20;
$R=255;
}
$data = GetImageSize($srcFile,&$info);
switch ($data[2]) {
case 1: //图片类型,1是GIF图
$im = @ImageCreateFromGIF($srcFile);
break;
case 2: //图片类型,2是JPG图
$im = @imagecreatefromjpeg($srcFile);
break;
case 3: //图片类型,3是PNG图
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$ni= imagecreatetruecolor($srcW,$srcH);
imagecopyresampled($ni,$im,0,0,0,0,$srcW,$srcH,$srcW,$srcH);
$font = "2.ttf";
$textcolor = imagecolorallocate($ni,$R,$G,$B); // Set text color
$i=0;
$txt='''';
$len=ceil((12*22)/$size);
$lgg=ceil(($size*16)/12)-1;
while(strlen($txt)>0||!$i){
$start=$len*$i;
$kk=ceil($size*13/12);
//$kk=13;
$txt=substr($text, $start, $len);
$hei=$i*$lgg+$kk;
imagettftext($ni,$size, 0, 8, $hei, $textcolor, $font, $txt); // Write the text with a font
$i++;
}
ImageJpeg($ni);
}
if(!$size||$size<1)$size=12;
makethumb("face.jpg",$text,$size,$R,$G,$B);
?>
Header( "Content-type: image/jpeg");
function makethumb($srcFile,$text,$size=12,$R=0,$G=0,$B=0) {
if(!$text){
$text=''welcome to imbbs.cn'';
$size=20;
$R=255;
}
$data = GetImageSize($srcFile,&$info);
switch ($data[2]) {
case 1: //图片类型,1是GIF图
$im = @ImageCreateFromGIF($srcFile);
break;
case 2: //图片类型,2是JPG图
$im = @imagecreatefromjpeg($srcFile);
break;
case 3: //图片类型,3是PNG图
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$ni= imagecreatetruecolor($srcW,$srcH);
imagecopyresampled($ni,$im,0,0,0,0,$srcW,$srcH,$srcW,$srcH);
$font = "2.ttf";
$textcolor = imagecolorallocate($ni,$R,$G,$B); // Set text color
$i=0;
$txt='''';
$len=ceil((12*22)/$size);
$lgg=ceil(($size*16)/12)-1;
while(strlen($txt)>0||!$i){
$start=$len*$i;
$kk=ceil($size*13/12);
//$kk=13;
$txt=substr($text, $start, $len);
$hei=$i*$lgg+$kk;
imagettftext($ni,$size, 0, 8, $hei, $textcolor, $font, $txt); // Write the text with a font
$i++;
}
ImageJpeg($ni);
}
if(!$size||$size<1)$size=12;
makethumb("face.jpg",$text,$size,$R,$G,$B);
?>
最新技术文章: