PHP单用户微博程序源码整理
单用户微博程序源码
数据库结构(共三张
:w_comment、w_log、w_online)
主页index.php源码
$v)$s[$k]=rs($v);
}else{
$s=stripslashes($s);
}
return $s;
}
1
$_GET=rs($_GET);$_POST=rs($_POST);$_COOKIE=rs($_COOKIE);
}
/*=======系统配置开始=======*/
$db_host='localhost';//MYSQL数据库服务器
$db_user='root';//MYSQL数据库用户
$db_password='';//MYSQL数据库用户密码
$db_name='miniblog';//MYSQL数据库名称
$db_prefix='w_';//MYSQL数据表前缀
$rewrite=false;//是否开启路径重写规则
$rewrite_ext='html';//重写文件名后缀
$password='admin';//管理登录密码
$online_overtime=30;//在线
超时时间间隔(分钟)
/*=======系统配置结束=======*/
//检查是否非法提交
function check_request(){
if(empty($_SERVER['HTTP_REFERER'])||(preg_replace("/https?:\/\/([^\:\/]+).*/i","\\1",$_S
ERVER['HTTP_REFERER'])!=preg_replace("/([^\:]+).*/", "\\1",$_SERVER['HTTP_HOST']))){
exit('Access Denied!');
}
}
//过滤非法字符
function filter_badwords($content,$badwords){
$words=explode(",",$badwords);
$words_count=count($words);
$words_tmep=$content;
for($i=0;$i<$words_count;$i++){
$replace_tmep=explode("=",$words[$i]);
$words_tmep=str_replace($replace_tmep[0],$replace_tmep[1],$words_tmep);
}
return $words_tmep;
}
//获取当前文件名
function get_self(){
return
isset($_SERVER['PHP_SELF'])?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME'];
}
//获取IP
function get_ip(){
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
//从IP.CN获取IP物理地址
function get_ip_address($ip){
if($ip=='127.0.0.1')return 'IP:'.$ip.' 来自:本地';
$content=@file_get_contents(";ip_url=".$ip);
return str_replace("您查询的IP是","IP",iconv("GB2312","UTF-8//IGNORE",$content));
}
//格式化日期时间
function format_datetime($time){
2
$now=time()-$time;
if($now<60){
return $now.' 秒前';
}elseif($now<3600){
return intval($now/60).' 分钟前';
}elseif($now<86400){
return intval($now/3600).' 小时前';
}else{
return date('Y-m-d H:i:s',$time);
}
}
//分页程序
function pager($page_name,$page_parameters='',$page_current,$page_size,$log_count){
global $config;
parse_str($page_parameters);
$page_count =ceil($log_count/$page_size);
$page_start =$page_current-2;
$page_end =$page_current+2;
if($page_current<3){
$page_start =1;
$page_end =3;
}
if($page_current>$page_count-2){
$page_start =$page_count-4;
$page_end =$page_count;
}
if($page_start<1)$page_start=1;
if($page_end>$page_count)$page_end=$page_count;
$html="";
$html.="";
return $html;
}
//获取操作系统
function get_os()
{
$AGENT=$_SERVER["HTTP_USER_AGENT"];
if(strpos($AGENT,"Windows NT 5.0"))$os="Windows 2000";
elseif(strpos($AGENT,"Windows NT 5.1"))$os="Windows XP";
elseif(strpos($AGENT,"Windows NT 5.2"))$os="Windows 2003";
elseif(strpos($AGENT,"Windows NT 6.0"))$os="Windows Vista";
elseif(strpos($AGENT,"Windows NT 6.1"))$os="Windows 7";
elseif(strpos($AGENT,"Windows NT"))$os="Windows NT";
elseif(strpos($AGENT,"Windows CE"))$os="Windows CE";
elseif(strpos($AGENT,"ME"))$os="Windows ME";
elseif(strpos($AGENT,"Windows 9"))$os="Windows 98";
elseif(strpos($AGENT,"unix"))$os="Unix";
elseif(strpos($AGENT,"linux"))$os="Linux";
elseif(strpos($AGENT,"SunOS"))$os="SunOS";
elseif(strpos($AGENT,"OpenBSD"))$os="OpenBSD";
elseif(strpos($AGENT,"FreeBSD"))$os="FreeBSD";
elseif(strpos($AGENT,"AIX"))$os="AIX";
elseif(strpos($AGENT,"Mac"))$os="Mac";
else $os="Other";
return $os;
}
//获取浏览器
function get_bs()
{
$AGENT=$_SERVER["HTTP_USER_AGENT"];
if(strpos($AGENT,"Opera"))$bs="Opera";
elseif(strpos($AGENT,"Firefox"))$bs="Firefox";
elseif(strpos($AGENT,"Chrome"))$bs="Chrome";
elseif(strpos($AGENT,"MSIE 6"))$bs="IE6";
elseif(strpos($AGENT,"MSIE 7"))$bs="IE7";
elseif(strpos($AGENT,"MSIE 8"))$bs="IE8";
else $bs="Other";
return $bs;
}
//获取在线信息
function set_online(){
if($GLOBALS['db']->getcount("select * from ".$GLOBALS['db_prefix']."online where
onlineip='".get_ip()."'")>0){
$sql="update ".$GLOBALS['db_prefix']."online set onlinetime='".$_SERVER['REQUEST_TIME']."',onlineagent='".get_os()."/".get_bs()."' where
onlineip='".get_ip()."'";
}else{
$sql="insert into ".$GLOBALS['db_prefix']."online(onlinetime,onlineip,onlineagent)
values('".$_SERVER['REQUEST_TIME']."','".get_ip()."','".get_os()."/".get_bs()."');";
}
$GLOBALS['db']->query($sql);
$GLOBALS['db']->delete("".$GLOBALS['db_prefix']."online","onlinetime
db_link=@mysql_connect($db_host, $db_user, $db_password,true) or
exit("Can't connect MySQL server($db_host)!");
@mysql_select_db($db_name,$this->db_link) or exit("Can't select
MySQL database($db_name)!");
@mysql_query("set names 'utf8'",$this->db_link);
$this->db_name=$db_name;
}
function __destruct(){
if($this->db_link)@mysql_close($this->db_link);
}
function query($sql){
return mysql_query($sql,$this->db_link);
}
function insert($table,$values,$debug=false){
$ks='';
$vs='';
foreach($values as $key => $value){
$ks.=$ks?",`$key`":"`$key`";
$vs.=$vs?",'$value'":"'$value'";
}
$sql="insert into `$table` ($ks) values ($vs)";
if($debug)return $sql;
return $this->query($sql);
}
function update($table,$values,$where='',$debug=false){
$v='';
foreach($values as $key => $value){
$v.=$v?",`$key`='$value'":"`$key`='$value'";
}
$sql="update `$table` set $v where $where";
if($debug)return $sql;
return $this->query($sql);
}
function delete($table,$where='',$debug=false){
if(empty($where)||$where==''){
$sql="delete from $table";
}else{
$sql="delete from $table where $where";
}
if($debug)return $sql;
return $this->query($sql);
}
function getcount($sql){
return mysql_num_rows($this->query($sql));
}
function getall($sql){
$temp;
$result =$this->query($sql);
if ($result){
$array = array();
5
while ($row = mysql_fetch_assoc($result)){
$array[] = $row;
}
$temp=$array;
mysql_free_result($result);
}else{
$temp=false;
}
return $temp;
}
function getone($sql){
$temp;
$result=$this->query($sql);
if ($result){
$temp=mysql_fetch_array($result);
mysql_free_result($result);
}else{
$temp=false;
}
return $temp;
}
function getdata(){
$res=mysql_list_tables($this->db_name);
while ($row = mysql_fetch_row($res))$table[]=$row[0];
$sql='';
foreach ($table as $v){
$sql.="DROP TABLE IF EXISTS `$v`;\n";
$rs=mysql_fetch_row(mysql_query("show create table $v"));
$sql.=$rs[1].";\n\n";
}
foreach ($table as $v){
$res=$this->query("select * from $v");
$fild=mysql_num_fields($res);
while ($rs=mysql_fetch_array($res)){
$comma="";
$sql.="insert into $v values(";
for($i=0;$i<$fild;$i++){
$sql.=$comma."'".mysql_escape_string($rs[$i])."'";
$comma = ",";
}
$sql.=");\n";
}
$sql.="\n";
}
return $sql;
}
function insert_id(){
return mysql_insert_id($this->db_link);
}
function version(){
return mysql_get_server_info($this->db_link);
}
}
//检查是否登录
function check_login(){
if(!isset($_SESSION['login'])||$_SESSION['login']!=true)
{
6
session_destroy();
exit("");
}
}
function goto($url,$text){
page_header();
echo("");
echo('
');
echo('');
echo("{$text}");
echo('
');
echo('
');
page_footer();
exit();
}
function alert($text){
page_header();
echo("");
echo('
');
echo('');
echo("{$text}");
echo('
');
echo('
');
page_footer();
exit();
}
//页面头部
function page_header(){
echo('');
echo('');
echo('');
echo('');
echo('');
?>
echo('Seven's Home !');
echo('');
echo('');
echo('');
echo('');
}
//页面尾部
function page_footer(){
echo("
");
echo("");
echo('