又一款php分页类代码

 更新时间:2016年11月25日 17:33  点击:1358
以前写过很多php 分页类但是今天这款分页程序我感觉是很好的,简洁实用,代码合理并没有多余的代码,是一款不错分页类函数哦。
 代码如下 复制代码

class multipage {

 var $total;
 var $perpage;
 var $pages;
 var $maxpage;
 var $offset = 9;
 var $curr_page;
 
 function init($total, $perpage, $maxpage) { //初始化页数
  $this->total;
  $this->perpage;
  $this->maxpage;
  $this->offset = 9;
 }
 
 function getpagelist() {//获取分页列表
  $result_pages = "";
  $this->pages = ceil($this->total / $this->perpage);
  
  if ($this->pages > $this->maxpage) {
   $from = $this->curr_page - $this->offset;
   if ($from < 1) {
    $from = 1;
   }
   $to = $from + $this->maxpage - 1;
   if ($to > $this->pages) {
    $to = $this->pages;
    if (($to - $from) < $this->maxpage) {
     $from = $from - 1;
    }
   }
  } else {
   $from = 1;
   $to = $this->pages;
  }
  
  $p = 0;
  for($i = $from; $i <= $to; $i++) {
   $result_pages[$p] = $i;
   $p++;
  }
  
  return $result_pages;
 }
 
 function getfirst() { //获取第一页
  if ($this->curr_page > 1 && $this->pages > 1) {
   return 1;
  } else {
   return "";
  }
 }
 
 function getlast() { //取末页
  if ($this->pages > 1 && $this->curr_page < $this->pages) {
   return $this->pages;
  } else {
   return "";
  }
 }
 
 function getprev() {//上一页
  $prevpage = $this->curr_page - 1;
  if ($prevpage > 0) {
   return $prevpage;
  } else {
   $prevpage = "";
   return $prevpage;
  }
 }
 
 function getnext() {//下一页
  $nextpage = $this->curr_page + 1;
  if ($nextpage <= $this->pages) {
   return $nextpage;
  } else {
   $nextpage = "";
   return $nextpage;
  }
 }
 
 function gettotal() {//共多少页
  if ($this->pages > 0) {
   return $this->pages;
  } else {
   return 1;
  }
 }
 
}

//分页类的使用方法

$page = new multipage();
$page->gettotal(); //总页娄
$page->getnext();//下一页

 

本文章为你提供一款经典的php文件上传类了,并且举例验证了这一款文件上传代码是可用的哦。
 代码如下 复制代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
  <label for="filefield"></label>
  <input type="file" name="filefield" id="filefield" />
  <input type="submit" name="button" id="button" value="文件开始上传" />
</form>
</body>
</html>

<?
/*

|   @param: $dir      -- 存放目录,最后加"/" [字串]
|   @param: $file_var -- 表单变量 [字串]
|   @param: $max_size -- 设定最大上传值,以k为单位. [整数/浮点数]
|   @param: $type     -- 限定后辍名(小写),多个用"/"隔开,不限定则留空 [字串]
|   @param: $name     -- 上传后命名,留空则为原名,true为系统随机定名 [布林值]
|   return: 上传后文件名
*/

function _asupfiles($dir, $file_var, $max_size='', $type='', $name=false)
{
if (!file_exists($dir)) showmsg("上传图片失败:上传目录 ".$dir." 不存在!",0);
if (!is_writable($dir))
{
showmsg("上传图片失败:上传目录 ".$dir." 无法写入!",0);
exit();
}
$upfile=& $_files["$file_var"];
$upfilename =  $upfile['name'];
if (!($upfilename===''))
{
if (!is_uploaded_file($upfile['tmp_name']))
{
showmsg('上传图片失败:你选择的文件无法上传',0);
exit();
}
if ($max_size>0 && $upfile['size']/1024>$max_size)
{
showmsg("上传图片失败:文件大小不能超过  ".$max_size."kb",0);
exit();
}
$ext_name = strtolower(str_replace(".", "", strrchr($upfilename, ".")));
if (!($type==='') && strpos($type, $ext_name)===false)
{
showmsg("上传图片失败:只允许上传 ".$type." 的文件!",0);
exit();
}
($name==true)?$uploadname=time().mt_rand(100,999).".".$ext_name :'';
($name==false)?$uploadname=$upfilename:'';
!is_bool($name)?($uploadname=$name.".".$ext_name):'';
//$uploadname = $name ? md5(uniqid(rand())).".".$ext_name : $upfilename;
if (!move_uploaded_file($upfile['tmp_name'], $dir.$uploadname))
{
showmsg('上传图片失败:文件上传出错!',0);
 exit();
}
return $uploadname;
}
else
{
return '';
}
}
?>

这是一款完整理的php登录代码实例哦,他从数据库到html以及php程序,整个过程都一步步写出来了,是一款非常不错的入门级登录php代码。
 代码如下 复制代码

session_start();

/* get post */  
 if (!function_exists("getpost")){function getpost(){if(count($_post)){foreach($_post as $key => $value){global ${$key};${$key}=$value;}}}}

/* get get */  
 if (!function_exists("getget")){function getget(){if(count($_get)){foreach($_get as $key => $value){global ${$key};$$key=($value);}}}}

/* sql escape string */
if (!function_exists("escapeit")){
function escapeit($text){ 
 if (get_magic_quotes_gpc()) $text=strips教程lashes($text);
 if (!is_numeric($text)) $text=mysql教程_real_escape_string($text);
 return $text;
}}
 
getpost(); //获取post过来的数据


//login

 代码如下 复制代码

$rs = $db->query("select * from `backend_user` where binary `login` = '".escapeit($login)."' and binary `password` = '".md5($password)."'");

if (mysql_num_rows($rs) > 0) {
 $row = $db->fetch_array($rs);
 $_session["smartinfo_sysid"] = $row["user_id"];
 $_session["smartinfo_syslogin"] = $row["login"];
 $db->query("update `backend_user` set `last_logon` = '".date("y-m-d h:i:s")."' where `id` = '".$row["id"]."'");
 header("location: index2.php");
} else {
 header("location: index.php?status=fail");
}

//利用到的函数

?>
html代码

 代码如下 复制代码

<table width="100%" height="100%" cellpadding="0" cellspacing="0"><tr><td>
  <table width="350" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" class="heading"><div style="font-size:12px;" align="left">control panel</div></td>
      </tr>
  </table>
  <table width="350" align="center" cellpadding="0" cellspacing="0" class="tableborder">
  <form action="login.php" method="post" name="login" id="login" onsubmit="return checkvalid(this);">
   
    <tr>
      <td align="center"><img src="images/logo.jpg" width="198" height="61"></td>
      </tr>
    <tr>
      <td class="c1" align="right" style="height:10px"></td>
    </tr>
    <tr><td><table width="85%" align="center" cellpadding="0" cellspacing="0">
 <tr>
      <td style="font-size:12px"><b>login id:</b></td>
      <td align="right"><input name="login" type="text" style="width:220px" ></td>
    </tr>
    <tr>
      <td style="font-size:12px"><b>password:</b></td>
      <td align="right"><input name="password" type="password" style="width:220px" size="2" maxlength="15"></td>
    </tr>
    <tr>
  <td></td>
      <td align="right" valign="top"><input type="submit" name="submit" id="submit" value="login" class="button"></td>
    </tr>
 </table></td></tr>
 <tr>
   <td class="c1" align="right" style="height:10px"></td>
 </tr>
  </form>
</table>
</td></tr></table>

数据库

--
-- 表的结构 `backend_user`
--

create table if not exists `backend_user` (
  `user_id` int(11) not null auto_increment,
  `group_id` int(11) not null default '0',
  `login` varchar(255) not null default '',
  `password` varchar(255) not null default '',
  `last_logon` datetime not null default '0000-00-00 00:00:00',
  primary key  (`user_id`)
) engine=myisam  default charset=utf8 auto_increment=2 ;

--
-- 导出表中的数据 `backend_user`
--

insert into `backend_user` (`user_id`, `group_id`, `login`, `password`, `last_logon`) values
(1, 0, 'admin', 'e10adc3949ba59abbe56e057f20f883e', '0000-00-00 00:00:00');

本教程是一款利用了php ajax无刷新验证用户输入的新闻标题是否己经存在了数据库中,如果是返回0否则就返回1
 代码如下 复制代码
<tr>
  <td align="center" bgcolor="#f6f6f6">新闻标题:</td>
  <td height="25" colspan="2" align="left" bgcolor="#f6f6f6" style="width: 367px">
      <input  name="title" id="title" onblur="startrequestusingpost();" type="text"/>
      <label id="message" style="color: red">该标题已存在</label>
      <label id="lbltitle" style="color: red">标题不能为空</label>                  </td>
  <td bgcolor="#f6f6f6">&nbsp;不能为空</td>
</tr>
 代码如下 复制代码

<script language="网页特效">
function startrequestusingpost() {
         if(checktitle()==false)
         {
               return;
         }
           var title = document.getelementbyid("title").value;
           createxmlhttprequest();
           xmlhttp.open("post","checkntype",true);
           xmlhttp.onreadystatechange = processresponse;
           xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
           xmlhttp.send("title=" + title);
      }
     
      function processresponse() {
           if(xmlhttp.readystate == 4) {
                if(xmlhttp.status == 200) {
                    var result = xmlhttp.responsetext;
              if(result==1){
                document.getelementbyid("message").style.display="inline";
                document.getelementbyid("btnadd").disabled="disabled";
                }else
                {
                  document.getelementbyid("message").style.display="none";
                 document.getelementbyid("btnadd").disabled="";
                 }
                }
           }
      }
      function checktitle()
      {
       var title=document.getelementbyid("title").value;
          if(title=="")
          {
           document.getelementbyid("lbltitle").style.display="inline";
            return false;
          }else
          {
          document.getelementbyid("lbltitle").style.display="none";
           return true;
       }
      }

</script>

php代码

 代码如下 复制代码
<?
$title = $_post['title'];
if( $title ='www.111cn.net')
{
 echo 1;
}
else
{
 echo 0;
}
?>

<?php教程
/*
ajax php 聊天室实例代码
但是必须基于以下条款:
  * 署名。你必须明确标明作者的名字。.
  * 非商业用途。 你不可将当前作品用于商业目的。
  * 保持一致。 如果你基于当前作品更改、变换或构造新作品,你应当按照与当前协议完全相同的协议分发最终作品
  * 对于任何二次使用或分发,你必须让其他人明确当前作品的授权条款
  * 在得到作者的明确允许下,这里的某些条款可以放弃

此约定是法律文本 (完整的协议)的简单易读概要
****************************************/
//****************参数设置****************
//显示在线用户

 代码如下 复制代码

$disonline = true;
//新登陆时显示最近内容的条数(默认为30条)
$leastnum = 30;
//默认的房间名(默认是每天换一个文件),如果去掉d,则是每月换一个文件
$room = date("y-m-d");
//房间保存路径,必须以/结尾
$roomdir = "rooms/";
//编码方式
$charset = "utf-8";
//客户端最大显示内容条数(建议不要太大)
$maxdisplay = 300;


//语言
$lang = array(
//聊天室描述
"description"=>"欢迎来到迷你ajax聊天室。最新版本 1.2。下载请到<a href='http://111cn.net' target=_blank>www.111cn.net</a>",
//聊天室标题
"title"=>"mini ajax chatroom by longbill",
//第一个到聊天室的欢迎
"firstone"=>"<span style='color:#16a5e9;'>welcome to longbill's mini ajax chatroom!</span>",
//当信息有禁止内容时显示
"ban"=>"i am a pig!",
//关键字
"keywords"=>"聊天室,迷你,小型,ajax,chat,chatroom,longbill,111cn.net,php,网页特效",
//发言提示
"hereyourwords" => "在这里发言!"
);

error_reporting(e_all ^ e_notice ^ e_warning);
header("content-type:text/html; charset=utf-8");

$get_past_sec = 3; //如果发现丢话,可以适当调大这个值
$touchs = 10; //检查在线人数的时间间隔

 

if (!function_exists("file_get_contents"))
{
 function file_get_contents($path)
 {
  if (!file_exists($path)) return false;
  $fp=@fopen($path,"r");
  $all=fread($fp,filesize($path));
  fclose($fp);
  return $all;
 }
}

if (!function_exists("file_put_contents"))
{
 function file_put_contents($path,$val)
 {
  $fp=@fopen($path,"w");
  fputs($fp,$val);
  fclose($fp);
  return true;
 }
}

 

$title = $lang["title"];
$earlier = 10;
$description = $lang["description"];
$origroom = $room;
$least = ($_get["dis"])?intval($_get["dis"]):$leastnum;
$touchme = $_post['touchme'];
if (!is_dir($roomdir)) @mkdir($roomdir) or die("error when creating folder $roomdir");
$room = $_get['room'];
if (!$room) $room = $_post["room"];
$room = checkfilename($room);
if (!$room) $room = $origroom;
$filename = $roomdir.$room.".dat.php";
$datafile = $roomdir.$room.".php";
if (!file_exists($filename)) @file_put_contents($filename,'<?php die();?>'." ".time()."|".$lang["firstone"]." ");
if (!file_exists($datafile)) @file_put_contents($datafile,'<?php die();?>'." ");
$action = $_post["action"];

function checkfilename($file)
{
 if (!$file) return "";
 $file = trim($file);
 $a = substr($file,-1);
 $file = eregi_replace("^[.\/]*","",$file);
 $file = eregi_replace("[.\/]*$","",$file);
 $arr = array("../","./","/","\","..\",".\");
 $file = str_replace($arr,"",$file);
 return $file;
}

 

[!--infotagslink--]

相关文章

  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • php怎么用拼音 简单的php中文转拼音的实现代码

    小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
  • php导出csv格式数据并将数字转换成文本的思路以及代码分享

    php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07
  • ecshop商品无限级分类代码

    ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25