【php开源代码栏目提醒】:网学会员php开源代码为您提供lib.php参考,解决您在lib.php学习中工作中的难题,参考学习。
<?PHP
$res = array();
#if you are using php 4.0.6 and earlier, uncomment this next line
# pre41vars();
require('config.php');
include_once("class.BlogInfo.php");
include_once("class.BlogEntry.php");
#open connection to DB
require_once("adodb/adodb-errorhandler.inc.php");
require_once("adodb/adodb.inc.php");
$db = NewADOConnection($dbtype);
$db->PConnect($host,$user,$passwd, $dbase);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
#
# use_new_vars - for <= php4.0.6 to set all
PHP variables to use $_ style in php > 4.1.x
#
function pre41vars() {
global $_REQUEST, $HTTP_GET_VARS, $_SESSION, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_POST_FILES, $_REQUEST, $_SESSION, $_SERVER, $_ENV, $_COOKIE, $_POST, $_GET, $_FILES;
$_COOKIE = $HTTP_COOKIE_VARS;
$_SESSION = $HTTP_SESSION_VARS;
$_ENV = $HTTP_ENV_VARS;
$_SERVER = $HTTP_SERVER_VARS;
$_GET = $HTTP_GET_VARS;
$_POST = $HTTP_POST_VARS;
$_FILES = $HTTP_POST_FILES;
if($HTTP_SERVER_VARS['REQUEST_METHOD'] == "GET") {
$_REQUEST = $HTTP_GET_VARS;
} else {
$_REQUEST = $HTTP_POST_VARS;
}
}
#
# escape - escapes input if magic quotes not turned on
#
function escape($var) {
if(!get_magic_quotes_gpc()) {
$var = addslashes($var);
}
return $var;
}
#
# auth - authenticates the user based on the session
#
function auth() {
global $_SESSION, $_SERVER;
if(!session_is_registered("login")) { #if login is ! in the session
header("Location: login.php?login\n\n");
} elseif(!session_is_registered("ip")) { # if the ip is ! in the session
header("Location: login.php?ip\n\n");
} elseif($_SESSION['ip'] != $_SERVER['REMOTE_ADDR']) { # if the ip in session is != to the ip of the client
header("Location: login.php?hijack\n\n");
error_log($_SERVER['REMOTE_ADDR']." - attempted session hijack\n",3,"security.log"); #log attempt
}
}
#
# isLoggedIn - sees if user is logged in based on the session
#
function isLoggedIn() {
global $_SESSION, $_SERVER;
if(session_is_registered("login") and ($_SESSION['ip'] == $_SERVER['REMOTE_ADDR'])) {
return 1;
} else {
return 0;
}
}
#
# adminemail - returns email address of admin user
#
function adminemail() {
global $db;
$sql = "SELECT email from blog_users where admin=1";
$res = $db->Execute($sql);
return $res->fields['email'];
}
#
# isAdmin - checks is user is admin user
#
function isAdmin() {
global $_SESSION, $db;
$sql = "select admin from blog_users where login='".$_SESSION['login']."'";
$res = $db->Execute($
sql);
return $res->fields['admin'];
}
#
# userHasRights - if user is in blog acl
#
function userHasRights($uid,$users) {
global $blogid;
if(isBlogAdmin($blogid) or isAdmin()) {
return 1;
} else {
foreach($users as $user) {
if($user->userId == $uid) {
return 1;
}
}
}
return 0;
}
#
# get_reqs - returns number of blog requests
#
function get_reqs() {
global $db;
$sql = "select count(*) as count from blog_request";
$res = $db->Execute($sql);
return $res->fields['count'];
}
#
# print_login - outputs login form
#
function print_login() {
global $baseurl;
echo "<div align=center>
<form action=\"$baseurl/login.php\" method=POST>
<table cellpadding=4 cellspacing=0 border=0 style=\"padding:4px;border:1px solid #999999;\">
<tr>
<td>
用户名:
</td>
<td>
<input type=text name=ulogin size=8>
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input type=password name=pass
word size=8>
</td>
</tr>
</table>
<input type=hidden name=act value=\"login\">
<input class=search type=submit value=\"登录\">
</form>
<p></p>
<a class=small href=\"login.php?act=change\">忘记密码?</a><p>
</div>
\n";
}
#
# 新增日志表单
#
function print_form() {
global $uid, $blogid, $use_weblog_rpc, $enable_trackback, $enable_pingback, $enable_smilies;
if($blogid) {
echo "
<p>
<form action=\"preview.php\" method=POST target=\"preview\" name=prev>
<input type=hidden name=etitle>
<input type=hidden name=body>
<input type=hidden name=blogid value=\"$blogid\">
<input type=hidden name=uid value=\"$uid\">
<input type=hidden name=cid>
<input type=hidden name=trans>
<input type=hidden name=format>
</form>
<form action=\"edit.php\" method=POST name=entry>
<p>
<table width=100%>
<tr>
<td colspan=2 bgColor=\"#dddddd\" style=\"border:1px solid #999999;\">
<b>添加新日志</b>
</td>
</tr>
<tr>
<td align=right bgcolor=\"#eeeeee\">
分类:
</td>
<td>".category_list()."</td>
</tr>
<tr>
<td align=right bgcolor=\"#eeeeee\">标题:</td>
<td><input type=text size=24 maxlength=32 name