本文實例講述了php中分頁及SqlHelper類用法。分享給大家參考,具體如下:
文檔目錄結構如下:
SqlHelper.php程式碼如下:
<?php /** * Created by JetBrains PhpStorm. * User: lee * Date: 13-7-26 * Time: 下午8:30 * To change this template use File | Settings | File Templates. */ class SqlHelper{ private $mysqli; private static $host="localhost"; private static $user="root"; private static $pwd=""; private static $db="world"; private $sql=false; private $result=false; function __construct(){ $this->mysqli=new MySQLi(self::$host,self::$user,self::$pwd,self::$db); if($this->mysqli->connect_error){ die("连接数据库失败! ".$this->mysql->connect_error); } $this->mysqli->query("set names utf8"); } function execute_dql_all($sql){ //执行查询语句 $arr=array(); $this->result=$this->mysqli->query($sql) or die ($this->mysql->connect_error); //将数据转存到$arr数组中 while($row=mysqli_fetch_array($this->result,MYSQL_BOTH)){ $arr[]=$row; } $this->result->free(); return $arr; } function execute_dql_num($sql){ //执行查询语句 $arr=array(); $this->result=$this->mysqli->query($sql) or die ($this->mysql->connect_error); //将数据转存到$arr数组中 while($row=mysqli_fetch_array($this->result,MYSQLI_NUM)){ $arr[]=$row; } $this->result->free(); return $arr; } function execute_dql_assoc($sql){ //执行查询语句 $arr=array(); $this->result=$this->mysqli->query($sql) or die ($this->mysql->connect_error); //将数据转存到$arr数组中 while($row=mysqli_fetch_array($this->result,MYSQLI_ASSOC)){ $arr[]=$row; } $this->result->free(); return $arr; } //查询某表中的记录数 function execute_dql_counts($table,$id="*"){ $this->sql="select count($id) from $table"; $this->result=$this->mysqli->query($this->sql); $row=mysqli_fetch_all($this->result); $this->result->free(); return $row[0][0]; } function execute_dml($sql){ //执行正删改 $this->result=$this->mysqli->query($sql); if(!$this->result){ return -1;//执行正删改失败 }else{ if($this->mysqli->affected_rows>0){ return 1;//执行正删改成功,影响行数 }else{ return 0;//执行正删改成功,但没有影响行数 } } } }
Paging.phplink.
<?php /** * Created by JetBrains PhpStorm. * User: lee * Date: 13-7-27 * Time: 下午2:48 * To change this template use File | Settings | File Templates. */ header("Content-type:text/html;charset=utf-8;"); require_once("SqlHelper.php"); class Paging { private $sqlHelper=false; private $pageCount=false;//页数 private $counts=false;//总记录数 private $returnArr=false;//分页超链接的分页 function __construct(){ $this->sqlHelper=new SqlHelper(); $this->returnArr=array(); } /* * 参数说明 * * $table 分页时对那个表的数据分页 * $id 辅助查询当前分页的数据表的总记录数 * $pageSize 每页显示多少条信息记录数 * $pagingSize 分页栏每次循环显示出来的个数 * $nowPage 当前是第几页,默认第一页 * $href 分页栏的超链接将要往哪里连接 */ function paging_prev_next($table,$id="*",$pageSize,$pagingSize,$nowPage=1,$href){ $this->counts=$this->sqlHelper->execute_dql_counts($table,$id); $this->pageCount=ceil($this->counts/$pageSize); $this->returnArr["count"]=$this->counts; $this->returnArr["start"]=($nowPage-1)*$pageSize; $this->returnArr["limit"]=$pageSize; if($nowPage>$this->pageCount || $nowPage<=0){ return false; } $t=(ceil($nowPage/$pagingSize)-1)*$pagingSize+1; $pre=$nowPage-$pagingSize; $nex=$nowPage+$pagingSize; echo " <span class='paging-list-a paging-list-a-withBg'>{$nowPage}/{$this->pageCount}</span> <a href='{$href}?nowPage={$pre}' class='paging-list-a'><</a>"; for($i=$t;$i<$t+$pagingSize;$i++){ if($i*$pageSize>$this->pageCount*$pageSize){ break; }else{ if($nowPage==$i){ echo " <a href='{$href}?nowPage={$i}' class='paging-list-a paging-list-a-withBg'>{$i}</a>"; }else{ echo " <a href='{$href}?nowPage={$i}' class='paging-list-a'>{$i}</a>"; } } } echo " <a href='{$href}?nowPage={$nex}' class='paging-list-a'>></a>"; return $this->returnArr; } }
/** * Created by JetBrains PhpStorm. * User: lee * Date: 13-7-27 * Time: 下午5:56 * To change this template use File | Settings | File Templates. */ .paging-list-a{ border:1px solid #b5b5af; background-color:#efebed; font-family: 'Meiryo UI'; font-size: 16px; font-weight: 600; padding: 0px 8px 0px 8px; /*cursor: pointer;*/ text-decoration: none; color: #292927; } .paging-list-a-withBg{ background-color: #1D92E2; color: white; }Paging.php連結.
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" type="text/css" href="paging-list-link.css"> </head> <body> <?php header("Content-type:text/html;charset=utf-8;"); require_once 'Paging.php'; $paging=new Paging(); //参数说明 /* * $table 分页时对那个表的数据分页 * $id 辅助查询当前分页的数据表的总记录数 * $pageSize 每页显示多少条信息记录数 * $pagingSize 分页栏每次循环显示出来的个数 * $nowPage 当前是第几页,默认第一页 * $href 分页栏的超链接将要往哪里连接,当前页链接地址 */ //控制起始页为 $nowPage=1; if(isset($_GET["nowPage"])){ $nowPage=$_GET["nowPage"]; } //定义分页所需参数 $meiyexiansi=10; $meiyelianjieshu=10; $receiveArr=array(); $receiveArr=$paging->paging_prev_next("city","ID",$meiyexiansi,$meiyelianjieshu,$nowPage,"usePaging.php"); //容错判断 if(!$receiveArr){ return; } //查询每页需要显示的数据,大小限制存在 $receiveArr 数组中 $sqlHelper=new SqlHelper(); $result=$sqlHelper->execute_dql_num("select * from city limit ".$receiveArr['start'].",".$receiveArr['limit'].""); echo "<pre class="brush:php;toolbar:false">"; print_r($result); echo ""; ?>

tostartaphpsession,usesesses_start()attheScript'Sbeginning.1)placeitbeforeanyOutputtosetThesessionCookie.2)useSessionsforuserDatalikeloginstatusorshoppingcarts.3)regenerateSessiveIdStopreventFentfixationAttacks.s.4)考慮使用AttActAcks.s.s.4)

會話再生是指在用戶進行敏感操作時生成新會話ID並使舊ID失效,以防會話固定攻擊。實現步驟包括:1.檢測敏感操作,2.生成新會話ID,3.銷毀舊會話ID,4.更新用戶端會話信息。

PHP会话对应用性能有显著影响。优化方法包括:1.使用数据库存储会话数据,提升响应速度;2.减少会话数据使用,只存储必要信息;3.采用非阻塞会话处理器,提高并发能力;4.调整会话过期时间,平衡用户体验和服务器负担;5.使用持久会话,减少数据读写次数。

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

phpIdentifiesauser'ssessionSessionSessionCookiesAndSessionId.1)whiwsession_start()被稱為,phpgeneratesainiquesesesessionIdStoredInacookInAcookInAcienamedInAcienamedphpsessIdontheuser'sbrowser'sbrowser.2)thisIdallowSphptpptpptpptpptpptpptpptoretoreteretrieetrieetrieetrieetrieetrieetreetrieetrieetrieetrieetremthafromtheserver。

PHP會話的安全可以通過以下措施實現:1.使用session_regenerate_id()在用戶登錄或重要操作時重新生成會話ID。 2.通過HTTPS協議加密傳輸會話ID。 3.使用session_save_path()指定安全目錄存儲會話數據,並正確設置權限。

phpsessionFilesArestoredIntheDirectorySpecifiedBysession.save_path,通常是/tmponunix-likesystemsorc:\ windows \ windows \ temponwindows.tocustomizethis:tocustomizEthis:1)useession_save_save_save_path_path()


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中