当前位置:  编程技术>php
本页文章导读:
    ▪php 分页类(源码+实例)      1,php分页类代码 <?php /** * php分页类 * by www. */ //定义错误级别 error_reporting(E_ALL); //分页类 class pagination{ public $Start; // 开始mysql查询 public $End; // 结束mysql查询 private $Number; //.........
    ▪php连接mysql数据库的类(接口实现)      php与mysql连接类的代码分享,如下: <?php /** * @连接mysql数据库的类 * @filename:Class_Con.inc.php * * @example $this -> Link (); */ //接口定义 interface Connected { // Buat Bayangan Pertama.........
    ▪分享一个php 验证码类及调用示例      1,php验证码类 <?php // usage: /* 显示验证码: <img src="/blog_article/captcha_php_cap=login.png"> 检查验证码: 检查输入的验证码与 $_SESSION['login'] 中保存的值是否相等。 */ error_reporting(E_ALL); session_s.........

[1]php 分页类(源码+实例)
    来源: 互联网  发布时间: 2013-12-24

1,php分页类代码

<?php
/**
* php分页类
* by www.
*/

//定义错误级别
error_reporting(E_ALL); 

//分页类
class pagination{ 
public  $Start;  // 开始mysql查询
public  $End;  // 结束mysql查询
private $Number;  //分布数据的数量 
public  $Pages; // 页数
private $N_p_p;  //每页要显示的内容数量 
private $Page_number; //当前页数 
private $Buttons; //最大显示的按钮数,即每页面中显示出的页数

function __construct($number,$n_p_p=10,$page_number=1,$buttons=5) 
{ 
     
    //page start from 1
    $page_number    =    ($page_number<1)    ?    1    :    $page_number    ;
    $this->        Number        =    $number;
    $this->        N_p_p        =    $n_p_p; 
    $this->        Pages        =    ceil    (    $this->    Number    /    $this->    N_p_p    )    ; 
    $this->        Buttons        =    $buttons        ; 
    $page_number=    ($page_number>$this->Pages)    ?    $this->Pages    :    $page_number    ; 
    $this->        Page_number    =    $page_number    ; 
    $this->        Ret()    ; 
    } 

 public function Show_Pagination($link,$get='page',$div_class_name='pagination') 
    { 

    //if pages == 1 , no need to print pagination 
    if($this->Pages==1)return; 
    //$link is the addres of current page      
    //$get is name of get method 
    //echo pagination's div 
     
    echo'<div .$div_class_name.'">'; 
    //echo pre button 
     
    if($this->Page_number>1)echo '<a  href="'.$link.'&'.$get.'='.($this->Page_number -1 ).'">Per</a> '; 
    else echo '<a >Per</a> '; 
     
    //print button
    $this->Buttons=(int)$this->Buttons;
    $start_counter    =    $this->Page_number-floor($this->Buttons/2);//for normal mode
    $end_conter        =    $this->Page_number+floor($this->Buttons/2);//for normal mode
    //try to buttons exactly equal to $Buttons    
    if($start_counter<1) $end_conter=$end_conter+abs($start_counter);
    if($end_conter>$this->Pages) $start_counter=$start_counter-($end_conter-$this->Pages);
    if(($this->Page_number-floor($this->Buttons/2))<1)$end_conter ++;     
     
    for ($i=$start_counter;$i<=$end_conter;$i++) 
{ 
     
if($i>$this->Pages || $i<1)continue;        //no print less than 1 value or grater than totall page 
     
if($i==$this->Page_number)echo ' <a  >'.$i.'</a> ';         // change current page' class 
     
else echo ' <a  href="'.$link.'&'.$get.'='.$i.'">'.$i.'</a> ';      // normal pages 
     
} 
      
    //echo next button 
     
    if($this->Page_number<$this->Pages)echo '<a  href="'.$link.'&'.$get.'='. ($this->Page_number +1 ) .'">Nex</a> '; 
     
    else echo '<a >Nex</a> ';         
     
    //close div tag 
     
    echo'</div>'; 
     
    } 


    //give the page number and return start and end of selection  

 private function  Ret() 
    { 

    $this->Start=(($this->Page_number-1)*$this->N_p_p); 

    $this->End=  $this->N_p_p ; 

    } 
}

2,分页类的示例一

<html> 
<head> 
<style type="text/css"> 
/* style for show*/ 
.pagination{direction:ltr} 
.pagination a{border-radius:3px;background-color:#eee;color:#555;border:1px solid #aaaaaa;padding-top:2px;padding-bottom:2px;
padding-right:5px;padding-left:5px;text-decoration:none;} 
.pagination a:hover ,.pagination .cur{border-color:#0C52CE;color:#0C52CE;background-color:#fff;} 
</style> 
<title>php分页类示例---www.</title> 
</head> 

<?php  
//include class: 
require_once"pagination.php"; 

//get the numbet of current page 
//note! you should  safe it  
if(isset($_GET['page'])){ 
$page=$_GET['page']; 
} 
else $page=1; 

//connect to db ... 
mysql_connect("localhost","root","");//use your host,username and password to connect to the db 

mysql_select_db("dbname");//select your database 

//run query to get number of all records 
$query=mysql_query("select count(id) from table"); //raplace table with your table name 
$totall=mysql_result($query,0); 

//creat new object 
$pagination=new pagination($totall,3 /*number of content per page*/,$page,5 /*number of button to show*/); 

//get records of current page 
$SecondQuery=mysql_query("select id from table order by id desc limit $pagination->Start , $pagination->End"); 

//echo your result 
while($row=mysql_fetch_assoc($SecondQuery)) 
    { 
        echo 'id='.$row['id'].'<br>'; 
     
    }
//show pagination: 
$pagination->Show_Pagination("ExampleMysql.php?param1=value1",'page','pagination'); 
?>

3,分页类的调用示例二

<html> 
<head> 
<style type="text/css"> 
/* style for show*/ 
.pagination{direction:ltr} 
.pagination a{border-radius:3px;background-color:#eee;color:#555;border:1px solid #aaaaaa;padding-top:2px;padding-bottom:2px;
|padding-right:5px;padding-left:5px;text-decoration:none;} 
.pagination a:hover ,.pagination .cur{border-color:#0C52CE;color:#0C52CE;background-color:#fff;} 
</style> 
<title>php分页类的调用示例-www.</title> 
</head> 
<?php  
//include分页类文件 
require_once "pagination.php"; 

//param of url to specify page_number 
$get_param='page'; 

//get current page from url 
$current_page=(isset($_GET[$get_param]) && is_numeric($_GET[$get_param]))?$_GET[$get_param]:1; 
//notice: when get param , youe should SAFE it  

//get totall available content   
// for example  you can get number of news from news table in database ( mysql_num_rows or count()) 
$totall_content=120; // for example 

//creat new cat object  
$cat=new pagination($totall_content,10 /*number of content per page*/,$current_page,5 /*number of button*/); 

//when you want to load content of page: for example in db queris : 

// select * from table where conditions order by key  limit $cat->Start , $cat->End 

//for show : 
$cat->Show_Pagination("example.php?",'page','pagination'); 
?> 
</html>

    
[2]php连接mysql数据库的类(接口实现)
    来源: 互联网  发布时间: 2013-12-24

php与mysql连接类的代码分享,如下:

<?php 
/** 
 * @连接mysql数据库的类
 * @filename:Class_Con.inc.php
 *  
 * @example $this -> Link ();  
 */ 

//接口定义
interface Connected 
{ 
 
// Buat Bayangan Pertama 
public function __construct(); 
 
// Buat Bayangan Function Kedua  
public function connect (); 
 
// Buat Bayangan Function Ketiga 
public function error_mysql (); 
 
// Buat Bayangan Function Keempat 
public function db_selected (); 
 
// Buat Bayangan Function Kelima  
public function mysql_close (); 
} 

/** 
 *  
 * 使用接品类操作mysql 
 *  
 * @return Function Dari Interface 
 * @var String Variable  
 */ 

class ConfigureMysql implements Connected{ 
 
/** 
 * @var String 
 */ 
var $_link ; 
 
/** 
 * @var String  
 */ 
var $_Link_Cons ;  
 
/** 
 * @var String  
 */ 
var $_Error;  
 
/** 
 * @var String  
 */ 
var $_DB;  
 
 
// Setting Function Dari Interface 
public function __construct() { 
 
$this ->_Link_Cons = $this ->connect(); 
return $this ->_Link_Cons ; 
} 
 
// Setting Function Kedua Dari Interface  
public function connect () { 
 
$this ->_link = @mysql_connect('localhost' , 'Faizal' , 'XXXXXXXXXXX' , '3306') or die($this->error_mysql ()); 
} 
 
// Settiong Function Ketiga Dari Interface  
public function error_mysql () { 
 
$this ->_Error = "<h2> Masalah Pada Koneksi Ke Jalur Mysql </h2>"; 
 
} 
 
// Settiong Function Keempat Dari Interface  
public function db_selected () { 
 
$this ->_DB = mysql_select_db('XXXXXXXX'); 
if ($this ->_DB != TRUE) { 
return $this ->error_mysql(); 
}else { 
return false ; 
} 
} 
 
// Setting Function Kelima Dari Interface  
public function mysql_close () { 
 
return mysql_close($this ->connect()); 
} 
} 

/** 
 * Gunakan Script Classes Untuk Function Parent::  
 *  
 * @example parent::__Construct(); 
 */ 

class LinkCon extends ConfigureMysql  { 
 
/** 
 * @var String 
 */ 
var $_Con ;  
 
/** 
 * @var String 
 */ 
var $_Db ; 
 
/** 
 * @magic Self:: 
 */ 
var  $_Error_Show ; 

/** 
 * @return Mysql_Close  
 */ 
var $_Close ; 
 
 
// Setting Function Dari Class Yang Di Extends 
public function Conf_Show_Mysql () { 
 
$this ->_Con = parent::__construct(); 
} 
 
// Setting Function Dari Class Yang Di Extends  
public function DB_Selected () { 
 
$this ->_Db = $this ->DB_Selected(); 
return $this ->_Db ; 
} 
 
// Setting Function Dari Class Yang Di Extends  
public function _CloseMysql () { 
 
$this ->_Close = $this ->mysql_close(); 
return $this ->_Close ; 
} 
 
// Set Error  
public function Eroor_Show () { 
 
$this ->_Error_Show = $this ->error_mysql();; 
return true ; 
} 
 
// Akhir Classes  
} 
?>
2,mysql类的调用示例:
<?php 
// Included File Classes Connected  
include("Class_Con.inc.php"); 
 
// Set Varibale Untuk Configure Data Classes  
$_Configure = new LinkCon(); 
 
// Set Variable Function  
$_Configure ->Conf_Show_Mysql(); 
 
// Set Variable Function  
$_Configure ->DB_Selected(); 
 
// Set Variable Function  
$_Configure ->_CloseMysql(); 
 
// Set Variable Function  
$_Configure ->Eroor_Show(); 
?>

    
[3]分享一个php 验证码类及调用示例
    来源: 互联网  发布时间: 2013-12-24

1,php验证码类

<?php 
// usage: 
/* 
显示验证码:
<img src="/blog_article/captcha_php_cap=login.png">

检查验证码:
检查输入的验证码与 $_SESSION['login'] 中保存的值是否相等。

*/
error_reporting(E_ALL);
session_start();
(!isset($_GET['cap']))?die('Error !'):1;
$captcha_array=array('login.png','contact.png','comment.png');
(!in_array($_GET['cap'],$captcha_array))?die('Error !'):1;
$captcha_cod=new captcha(basename($_GET['cap'],'.png'))   ;

//验证码类
class captcha
{
private $session_name;
private $image_width;
private $image_height;
private $cod_length;
private $cod_mode;
private $font_path;
private $avtage_font_size;
private $sec_cod;
private $res_image;

function __construct($name,$width=200,$height=50,$length=5,$mod=2,$font='arial.ttf',$av_font_size=25)
 {
 $this->   session_name  =  $name  ;
 $this->   image_width  =  $width  ;
 $this->   image_height  =  $height  ;
 $this->   cod_length  =  $length  ;
 $this->   mode    =  $mod  ;
 $this->   font_path  =  $font  ;
 $this->   avrage_font_size   =  $av_font_size   ;
 
 $this->Gen_Cod();
 }
  
function Write_Text($text)
{
  $x_pos=10;
  for($pos=0;$pos<strlen($text);$pos++)  {
    imagettftext($this->res_image,rand($this->avrage_font_size -2,$this->avrage_font_size +2),
    rand(-40,+40),$x_pos,rand(35,$this->image_height - $this->avrage_font_size),
    imagecolorallocate($this->res_image,rand(0,150),rand(0,150),rand(0,150)),
    $this->font_path,$text[$pos]);
    $x_pos+=($this->image_width/$this->cod_length);
 }
}
  
function Draw_Line()
{
  //
  for($pos=0;$pos<$this->image_height;$pos+=8)
  imageline($this->res_image,0,$pos,$this->image_width,$pos,imagecolorallocate($this->res_image,rand(200,230),rand(200,230),rand(200,230)));
  
  //
  for($pos=0;$pos<$this->image_width;$pos+=8)
  imageline($this->res_image,$pos,0,$pos,$this->image_height,imagecolorallocate($this->res_image,rand(200,230),rand(200,230),rand(200,230)));
}  
function Gen_Cod()
{
  //generate rand cod : 
  //mode:1   => 0-9      ,  mode:2   => 0-9 , a-z
  ($this->mode==1) ? $this->sec_cod=substr((string)rand(1000000000,9999999999),0,$this->cod_length) :
  $this->sec_cod=substr(md5(rand(1000000000,9999999999)),0,$this->cod_length);
  //set session :
  $_SESSION[$this->session_name]   =   $this->sec_cod   ;
   
   //creat image :
   $this->res_image=imagecreatetruecolor(   $this->image_width   ,   $this->image_height   );
      
   //fill color:
   imagefilledrectangle($this->res_image,0,0,$this->image_width,$this->image_height,imagecolorallocate($this->res_image,255,255,255));
   
   //write text :
   $this->Write_Text($this->sec_cod);
   
   //draw line :
   $this->Draw_Line();
   
   //output :
   imagejpeg($this->res_image);
   header('content-type:image/jpeg');
   
   //destroy:
   imagedestroy($this->res_image);
 }
}

2,php验证码类的调用示例:

<?php  
session_start(); 
if(isset($_POST['captchacod'])){ 
if($_SESSION['login']==$_POST['captchacod'])echo'<a >Your Entered Cod Was Correct</a><br>'; 
else echo'<a >Your Entered Cod Was Incorrect</a><br>'; 

} 
?> 
<img src="/blog_article/captcha_php_cap=login.png" > 
<form action="/blog_article/</php echo $_SERVER[.html'PHP_SELF']; //safe it later (xss)?>" method="post"> 
<a>INPUT TEXT :</a><br> 
<input type="text" name="captchacod"><br> 
<input type="submit" value="check"><br> 
</form>

您可能感兴趣的文章:
php验证码简单函数代码(附效果图)
php验证码的三个实例代码分享
一个php验证码的封装类
php自定义大小验证码的实例代码
php生成扭曲及旋转的验证码图片的实例代码
php仿QQ验证码的实现代码
php验证码函数使用的例子
php5验证码类(简易实用型)
php验证码(GD库生成验证码)的例子
php点击验证码实时刷新的实现代码
php图片验证码的例子
php彩色验证码的简单例子
php验证码刷新与局部刷新的实现方法
php GD库生成验证码的实例
php生成验证码的例子
php随机验证码 php生成随机验证码(图文)
一个比较稳定的php登陆系统验证码
用php生成带有雪花背景的验证码


    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3