首页 > php开发

php分页代码的原理

//为了避免重复包含文件而造成错误,加了判断函数是否存在的条件:
$page = $_get[page];
if(!function_exists(pageft)){
//定义函数pageft(),三个参数的含义为:
//$totle:信息总数;
//$displaypg:每页显示信息数,这里设置为默认是20;
//http://pic3.phprm.com/2010/09/11/$url.jpg:分页导航中的链接,除了加入不同的查询信息"page"外的部分都与这个url相同。
//   默认值本该设为本页url(即$_server["request_uri"]),但设置默认值的右边只能为常量,所以该默认值设为空字符串,在函数内部再设置为本页url。
function pageft($totle,$displaypg=20,$url=''){

阅读全文

php文件上传程序(支持缩略图)(1/2)

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>上传文件程序</title>
<style type="text/css教程">
*{
 font-size:12px;
 margin:0; padding:0;
}
a:link,a:visited{
 text-decoration:none;
 color: #393
}
a:hover{
 text-decoration:underline;
 color:#0033cc
}
input.text{
 border:1px solid #ccc;height:22px;line-height:22px;padding-left:5px;background:#fff;width:274px;
}
input.button{
 background:#fff url(http://pic4.phprm.com/2010/09/11/button.jpg);border:1px solid #9ea9c5;padding:2px 2px 0px 2px;margin-left:4px; margin-right:4px;
}
</style>
<script language=网页特效>
function check()
{
 var strfilename=document.myform.upfile.value;
 if (strfilename=="")
 {
     alert("请选择要上传的文件");
  document.myform.upfile.focus();
     return false;
   }
}
</script>
</head>

阅读全文

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.phprm.com/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

阅读全文

又一款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;
  }
 }
 
}

阅读全文

php登录代码

session_start();

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

阅读全文

php ajax仿dedecms 验证新闻是否存在

<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;
       }
      }

阅读全文