发新话题
打印

areone的php学习专用帖,高手拍砖

本主题由 .abu. 于 2008-9-3 12:53 置顶
接着来写留言本分页

如果这个分页学完了,差不多就可以做一个普通的企业站和一个小型的不带后台的cms了,带后台验证的功能,后面再加上来。小型的cms总结起来,也就是首页,列表页,内容页。

首页,实际上就是连接数据库然后调出相应的主题的标题和链接。幻灯片就是调出图片的的路径,标题,和链接。
列表页,就是我今天讲的这个,分页,后面会改成分页类来加载现成的函数,方便快速写一些小东西。
主题页,一般就是标题,发布时间,作者,内容,如果有优化的话,还会调出描述和关键字。其它的一些导航,版权类的东西,可以直接定义成全局的一些东西,也可以直接调出来。

好了,进入分页的写法,示例:
复制内容到剪贴板
代码:
<!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=utf-8" />   
<title>所有留言</title>   
<link rel="stylesheet" type="text/css" href="style.css" media="all" />   
</head>   
  
<body>   
<a href="add.php">发表留言</a>   
<?php   
require('common.php');   
$countRow = mysql_fetch_array(mysql_query("SELECT count(*) FROM gb_content"), MYSQL_BOTH);   
$count = $countRow[0]; //总行数   
$_GET['page'] = intval($_GET['page']);   
if ($_GET['page']<=0) {   
    $_GET['page'] = 1;   
}   
  
$lines = 10; // 每页行数   
$page = $_GET['page'];// 当前页   
$limit = ($page - 1) * $lines;//起启行   
$total = ceil($count/$lines); // 总页数   
$result = mysql_query("SELECT * FROM gb_content order by id desc limit " .$limit. ','.$lines.'');//查询数据   
  
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {// 取一条数据   
?>   
<table width="700" border="0" cellspacing="0" cellpadding="0" class="tb">   
  <tr>   
    <td class="bg"><b>[<?php echo htmlentities($row['username']) ?>]</b> 发表于:<?php echo htmlentities($row['insert_time']) ?></td>   
  </tr>   
  <tr>   
    <td><?php echo htmlentities($row['content']) ?></td>   
  </tr>   
  <tr>   
    <td align="right"><a href="edit.php?id=<?php echo $row['id'] ?>">修改</a> <a href="delete.php?id=<?php echo $row['id'] ?>">删除</a></td>   
  </tr>   
</table>   
<?php   
}   
mysql_free_result($result);   
if ($page>1) {   
    echo '<a href="?page=1">首页</a> <a href="?page='. ($page-1) .'">上一页</a>';   
}   
if ($page<$total) {   
    echo ' <a href="?page=' . ($page+1) .'">下一页</a> <a href="?page='.$total.'">末页</a>';   
}   
?>   
</body>   
</html>  

TOP

你最近学习有没有好点的分页类啊

TOP

回复 12# 的帖子

有的,后面会加上来,都是偷的别人的。我自己不太会写。

TOP

先插学一段生成静态页面的小代码来分析吧

一,PHP脚本与动态页面。

  PHP脚本是一种服务器端脚本程序,可通过嵌入等方法与HTML文件混合,也可以类,函数封装等形式,以模板的方式对用户请求进行处理。无论以何种方式,它的基本原理是这样的。由客户端提出请求,请求某一页面 -----> WEB服务器引入指定相应脚本进行处理 -----> 脚本被载入服务器 -----> 由服务器指定的PHP解析器对脚本进行解析形成HTML语言形式 ----> 将解析后的HTML语句以包的方式传回给浏览器。由此不难看出,在页面发送到浏览器后,PHP就不存在了,已被转化解析为HTML语句。客户请求为一动态文件,事实上并没有真正的文件存在在那里,是PHP解析而成相对应的页面,然后发送回浏览器。这种页面处理方式被称为“动态页面”。

  二,静态页面。

  静态页面是指在服务器端确实存在的仅含HTML以及JS,CSS等客户端运行脚本的页面。它的处理方式是。由客户端提出请求,请求某一页面 ----> WEB服务器确认并载入某一页面 ----> WEB服务器将该页面以包的形式传递回浏览器。由这一过程,我们对比一下动态页面,即可方现。动态页面需由WEB服务器的PHP解析器进行解析,而且通常还需连接数据库,进行数据库存取操作,然后才能形成HTML语言信息包;而静态页面,无须解析,无须连接数据库,直接发送,可大大减轻服务器压力,提高服务器负载能力,大幅提供页面打开速度和网站整体打开速度。但其缺点是,不能动态地对请求进行处理,服务器上必须确实存在该文件。
  三,模板及模板解析。

  模板即尚未填充内容html文件。例如:
   temp.html
复制内容到剪贴板
代码:
<HTML>
  <TITLE>{ title }</TITLE>
  <BODY>
     this is a { file } file's templets
  </BODY>
</HTML>
PHP处理:
templetest.php
复制内容到剪贴板
代码:
  <?php
  $title = "areone生成静态页面";
  $file   = "areone";
  $fp = fopen("temp.html","r");
  $content  = fread ($fp,filesize ("temp.html"));
  $content = str_replace ("{ file }",$file,$content);
  $content = str_replace ("{ title }",$title,$content);

  echo $content;
?>
模板解析处理,即将经PHP脚本解析处理后得出的结果填充(content)进模板的处理过程。通常借助于模板类。目前较流行的模板解析类有phplib,smarty,fastsmarty等等。模板解析处理的原理通常为替换。也有些程序员习惯将判断,循环等处理放进模板文件中,用解析类处理,典型应用为block概念,简单来说即为一个循环处理。由PHP脚本指定循环次数,如何循环代入等,再由模板解析类具体实施这些操作。

  好了,对比过静态页面与动态页面各自的优劣,现在我们就来说说,如何用PHP生成静态文件。

  PHP生成静态页面并不是指PHP的动态解析,输出HTML页面,而是指用PHP创建HTML页面。同时因为HTML的不可写性,我们创建的HTML若有修改,则需删掉重新生成即可。(当然你也可以选择用正则进行修改,但个人认为那样做倒不如删掉重新生成来得快捷,有些得不偿失。)

  言归正传。用过PHP文件操作函数的朋友知道,PHP中有一个文件操作函数fopen,即打开文件。若文件不存在,则尝试创建。这即是PHP可以用来创建HTML文件的理论基础。只要用来存放HTML文件的文件夹有写权限(即权限定义0777),即可创建文件。(针对UNIX系统而言,Win系统无须考虑。)仍以上例为例,若我们修改最后一句,并指定在test目录下生成一个名为test.html的静态文件:
复制内容到剪贴板
代码:
<?php
    $title = "areone生成静态页面";
   $file = "areone";

   $fp = fopen("temp.html","r");
   $content  = fread ($fp,filesize ("temp.html"));
   $content = str_replace ("{ file }",$file,$content);
   $content = str_replace ("{ title }",$title,$content);

    //echo $content;
   
   $filename = "test/test.html";
   $handle = fopen ($filename,"w"); //打开文件指针,创建文件
   /*
 检查文件是否被创建且可写
   */
   if (!is_writable ($filename)){
      die ("文件:".$filename."不可写,请检查其属性后重试!");
   }
   if (!fwrite ($handle,$content)){  //将信息写入文件
      die ("生成文件".$filename."失败!");
   }
   fclose ($handle); //关闭指针
   
   die ("创建文件".$filename."成功!");?>

TOP

啊旺同学脑子很好使
理解好呢透彻啊

TOP

  大鱼又夸我了。哈哈哈。我知道大鱼的php很牛的,我哪天不懂就追着你问。哈哈。

TOP

再补充一句,我叫阿万,不叫“啊旺”,你被kook带坏了。

TOP

接用写了

使用分页类来完成分页功能
复制内容到剪贴板
代码:
<!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=utf-8" />
<title>所有留言</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>

<body>
<a href="add.php">发表留言</a>
<?php
require('common.php');
require('lib/BluePage/BluePage.class.php');// 包含分页类

$count = $query->result($query->query("SELECT count(*) as count FROM gb_content"),'count');//总行数
$lines = 10; // 每页行数

$pBP  = new BluePage($count, $lines) ;// 实例化分页类
$aPDatas = $pBP->get();//分页返回结果
$limit = $aPDatas['offset'] ;//起始行

$result = $query->query("SELECT * FROM gb_content order by id desc limit " .$limit. ','.$lines.'');//查询数据

while ($row = $query->fetch_array($result)) {// 取一条数据
?>
<table width="700" border="0" cellspacing="0" cellpadding="0" class="tb">
  <tr>
    <td class="bg"><b>[<?php echo htmlentities($row['username']) ?>]</b> 发表于:<?php echo htmlentities($row['insert_time']) ?></td>
  </tr>
  <tr>
    <td><?php echo htmlentities($row['content']) ?></td>
  </tr>
  <tr>
    <td align="right"><a href="edit.php?id=<?php echo $row['id'] ?>">修改</a> <a href="delete.php?id=<?php echo $row['id'] ?>">删除</a></td>
  </tr>
</table>
<?php
}
$query->free_result($result);
$query->close();

$strHtml =  $pBP->getFull( $aPDatas);//html分页条
echo $strHtml ;// 输出
?>
</body>
</html>
里面其实调用了两个类,一个是数据库操作类,一个是分页类

也帖上来了

数据库操作类
复制内容到剪贴板
代码:
<?php
/**
* mysql查询类
*
*/
class dbQuery {
        /**
         * 查询总次数
         *
         * @var int
         */
        var $querynum = 0;
        /**
         * 连接句柄
         *
         * @var object
         */
        var $link;
        
        /**
         * 构造函数
         *
         * @param string $dbhost 主机名
         * @param string $dbuser 用户
         * @param string $dbpw   密码
         * @param string $dbname 数据库名
         * @param int $pconnect 是否持续连接
         */
        function dbQuery($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0) {
                if($pconnect) {
                        if(!$this->link = @mysql_pconnect($dbhost, $dbuser, $dbpw)) {
                                $this->halt('Can not connect to MySQL server');
                        }
                } else {
                        if(!$this->link = @mysql_connect($dbhost, $dbuser, $dbpw)) {
                                $this->halt('Can not connect to MySQL server');
                        }
                }
                if($this->version() > '4.1') {
                        global $dbcharset;
                        if($dbcharset) {
                                mysql_query("SET character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=binary", $this->link);
                        }

                        if($this->version() > '5.0.1') {
                                mysql_query("SET sql_mode=''", $this->link);
                        }
                }

                if($dbname) {
                        mysql_select_db($dbname, $this->link);
                }

        }
        /**
         * 选择数据库
         *
         * @param string $dbname
         * @return
         */
        function select_db($dbname) {
                return mysql_select_db($dbname, $this->link);
        }
        /**
         * 取出结果集中一条记录
         *
         * @param object $query
         * @param int $result_type
         * @return array
         */
        function fetch_array($query, $result_type = MYSQL_ASSOC) {
                return mysql_fetch_array($query, $result_type);
        }
        
        /**
         * 查询SQL
         *
         * @param string $sql
         * @param string $type
         * @return object
         */
        function query($sql, $type = '') {
               
                $func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ?
                        'mysql_unbuffered_query' : 'mysql_query';
                if(!($query = $func($sql, $this->link)) && $type != 'SILENT') {
                        $this->halt('MySQL Query Error', $sql);
                }

                $this->querynum++;
                return $query;
        }
        /**
         * 取影响条数
         *
         * @return int
         */
        function affected_rows() {
                return mysql_affected_rows($this->link);
        }
        /**
         * 返回错误信息
         *
         * @return array
         */
        function error() {
                return (($this->link) ? mysql_error($this->link) : mysql_error());
        }
        /**
         * 返回错误代码
         *
         * @return int
         */
        function errno() {
                return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
        }
        /**
         * 返回查询结果
         *
         * @param object $query
         * @param string $row
         * @return mixed
         */
        function result($query, $row) {
                $query = @mysql_result($query, $row);
                return $query;
        }
        /**
         * 结果条数
         *
         * @param object $query
         * @return int
         */
        function num_rows($query) {
                $query = mysql_num_rows($query);
                return $query;
        }
        /**
         * 取字段总数
         *
         * @param object $query
         * @return int
         */
        function num_fields($query) {
                return mysql_num_fields($query);
        }
        /**
         * 释放结果集
         *
         * @param object $query
         * @return bool
         */
        function free_result($query) {
                return mysql_free_result($query);
        }
        /**
         * 返回自增ID
         *
         * @return int
         */
        function insert_id() {
                return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
        }
        /**
         * 从结果集中取得一行作为枚举数组
         *
         * @param object $query
         * @return array
         */
        function fetch_row($query) {
                $query = mysql_fetch_row($query);
                return $query;
        }
        /**
         * 从结果集中取得列信息并作为对象返回
         *
         * @param object $query
         * @return object
         */
        function fetch_fields($query) {
                return mysql_fetch_field($query);
        }
        /**
         * 返回mysql版本
         *
         * @return string
         */
        function version() {
                return mysql_get_server_info($this->link);
        }
        /**
         * 关闭连接
         *
         * @return bool
         */
        function close() {
                return mysql_close($this->link);
        }
        /**
         * 输出错误信息
         *
         * @param string $message
         * @param string $sql
         */
        function halt($message = '', $sql = '') {
                echo $message . ' ' . $sql;
                exit;

        }
}

?>
分类页,这个分页类蛮经典的,好像是phpchina里面的。
复制内容到剪贴板
代码:
<?php
/*

* ----------------------------------------------------
* ID     : BluePage.class
* Author : Sam Teng <Sam@Bluessoft.com>
* ----------------------------------------------------
* Homepage: http://www.bluessoft.com/project/bluepage
* ----------------------------------------------------

*
*/

if ( ! class_exists ( "BluePage" ) )
{
    class BluePage
    {
            var $_total ;         // 记录总数
            var $_col ;           // 每页显示数
            var $_var  ;          // 分页变量,默认是page            
            var $_pos     = 3 ;   // 当前页在分页条中的位置
            var $_prefix  = '' ;  // 分页值的前填,比如 p123中的p
            var $_postfix = '' ;  // 分页值的后填,比如 123p中的p
            var $_symbol  = '&' ; // &或&
            var $_encode  = true ;// 是否对query string过滤
              
              var $_getlink = true ;  // 是否建造链接
              var $_getqs   = true ;  // 是否取Query String
              var $_qs      = '' ;         // Query String
              
              var $_order = 'f|pg|p|bar|ng|n|m' ;       // html的组合方式,参见配置文件
              var $_full  = 'f|pg|p|bar|n|ng|m|sl|i' ;  // Full
              var $_file  = 'Page.default.inc.php' ;    // 默认分页html配置文件,需要与Pager.class.php同路径
              
            /*
            参数说明:
                $intTotal     记录总数
                $intCol       每页显示数
                $strPageVar   页码变量
            */
            function BluePage ( $intTotal , $intCol , $strPageVar = 'page' )
            {
                    $this->_total = intval ( $intTotal ) ;
                    $this->_col   = intval ( $intCol ) ;
                    $this->_var   = $strPageVar ;
                    return true ;
            }
            
                /*
                参数说明:
                $intNum     显示多少个页码
               
                返回:
                $aPDatas[offset]   offset
                $aPDatas[m]        总页(最大页)数
                $aPDatas[m_ln]     总页(最大页)数 链接  需要$this->_getlink = true  以下相同
                $aPDatas[t]        当前页码
                $aPDatas[p]        上一页页码
                $aPDatas[p_ln]     上一页 链接
                $aPDatas[n]        下一页
                $aPDatas[n_ln]     下一页 链接
                $aPDatas[ng]       下一组页码
                $aPDatas[ng_ln]    下一组链接
                $aPDatas[qs]       Query String ?号后面部份,需要$this->_getqs = true ;
               
                当$this->_getlink = false 时:
                $aPDatas[bar]      分页条,一维数组
                当$this->_getlink = true 时:
                $aPDatas[bar]      多维数组,$aPDatas[bar][num] 分页数字   $aPDatas[bar][ln] 分页链接
                */
            function get( $intNum = 10 )
            {
                        $aPDatas = array( ) ;
                        if ( $this->_total < 1 || $this->_col < 1 )
                    {
                        $aPDatas[offset]   = 0 ;
                        $aPDatas[m]  = $aPDatas[p] = $aPDatas[n] = 1 ;
                        return $aPDatas ;
                    }
                    
                        ( $intThisPage = $this->getPage( $_REQUEST[$this->_var] ) ) > 1  
                        ? $aPDatas[t] = $intThisPage
                        : $aPDatas[t] = $intThisPage = 1 ;

                    if ( $this->_total < 1 || $this->_col < 1 )
                    {
                        $aPDatas[offset] = 0 ;
                        $aPDatas[t] = $aPDatas[m] = $aPDatas[p] = $aPDatas[n] = 1 ;
                    }
                    else
                    {
                            $aPDatas[offset]   = $this->_col * ( $intThisPage - 1 ) ;
                            $aPDatas[m]  = ceil ( $this->_total / $this->_col ) ;
                            $aPDatas[p]  = $intThisPage < 2 ? 1 : $intThisPage - 1 ;
                            $aPDatas[n] = $intThisPage == $aPDatas[m]
                                               ? $aPDatas[m]  : $intThisPage + 1 ;
                    }
                    
                    if ( $this->_getlink )
                    {
                            $this->getQueryString () ;
                            $aPDatas[m_ln]  = $this->setLink( $aPDatas[m] ) ;
                        $aPDatas[p_ln]  = $this->setLink( $aPDatas[p] ) ;
                        $aPDatas[n_ln] = $this->setLink( $aPDatas[n] ) ;
                    }
                    
                    $intNum = intval ( $intNum );
                    if ( $intNum )
                    {
                            $intSPage = ( $intSsPage = $intThisPage + 1 - $this->_pos ) < 1 ? 1 : $intSsPage ;
                            $intEPage = ( $intEsPage = $intSPage + $intNum - 1 ) > $aPDatas[m]
                                      ? $aPDatas[m] : $intEsPage ;
                            $aPDatas[pg]  = ( $intPGroup = $intThisPage - $intNum ) > 1 ?  $intPGroup  : 1 ;
                            $aPDatas[ng] = ( $intNGroup = $intThisPage + $intNum ) < $aPDatas[m] ? $intNGroup : $aPDatas[m] ;
                           
                            $arrPageBar = array ( ) ;
                            if ( $this->_getlink )
                            {
                                    $aPDatas[pg_ln] = $this->setLink( $aPDatas[pg] ) ;
                                    $aPDatas[ng_ln] = $this->setLink( $aPDatas[ng] ) ;
                                    $k = 0 ;
                                    for ( $i = $intSPage ; $i <= $intEPage ; $i++ )
                                    {
                                        $arrPageBar[$k]['num']  = $i ;
                                        $arrPageBar[$k]['ln'] = $this->setLink( $i ) ;
                                        $k++ ;
                                    }
                            }
                            else
                            {
                                    for ( $i = $intSPage ; $i <= $intEPage ; $i++ )
                                    {
                                        $arrPageBar[] = $i ;
                                    }
                                }
                            $aPDatas[bar]  = $arrPageBar ;
                           
                        }
                        if ( $this->_getqs )
                        {
                                if ( !$strQueryString )
                                {
                                $this->getQueryString() ;
                                $aPDatas[qs] = $this->_qs ;
                            }
                            else
                            {
                                    $aPDatas[qs] = $strQueryString ;
                            }
                        }
                        
                    return $aPDatas ;
            }
            
            function getFull( $aPDatas , $strHtmlFile = '' )
            {
                    $this->_order = $this->_full ;
                    return $this->getHTML( $aPDatas , $strHtmlFile ) ;
            }
            
            function getHTML( $aPDatas , $strHtmlFile = '' )
            {
                if ( $strHtmlFile == '' )
                {
                        $strHtmlFile = str_replace("\\" , "/", dirname( __FILE__ ) ) . '/'. $this->_file  ;
                };
                    if ( file_exists ( $strHtmlFile ) )
                    {
                            include ( $strHtmlFile ) ;
                            $aPA = explode( "|" , $this->_order ) ;
                            if ( is_array( $aPA )  )
                            {
                                    $strHtmlBody = '' ;
                                    foreach ( $aPA as $intPAkey )
                                    {
                                            switch ( $intPAkey )
                                            {
                                                    case 'm' :
                                                        $strHtmlBody .= sprintf( $PA[m] , $aPDatas[m_ln] , $aPDatas[m] ) ;
                                                            break ;
                                                    case 'f' :
                                                        $strHtmlBody .= sprintf( $PA[f] , $this->setLink(1) ) ;
                                                            break ;
                                                    case 'pg' :
                                                        if ( $aPDatas[t] > $this->_pos  )
                                                        $strHtmlBody .= sprintf( $PA[pg] , $aPDatas[pg_ln] ) ;
                                                            break ;
                                                    case 'p' :
                                                        $strHtmlBody .= sprintf( $PA[p] , $aPDatas[p_ln] ) ;
                                                            break ;
                                                    case 'bar' :
                                                        $strBar = '' ;
                                                        foreach ( $aPDatas[bar] AS $aPBar )
                                                        {
                                                                $strBar .= sprintf( $PA[bar] , $aPBar[ln] , $aPBar[num] ) ;
                                                        }
                                                        $strHtmlBody .= $PA[bar_head].$strBar.$PA[bar_end] ;
                                                        $strHtmlBody .= sprintf( $PA[bar_s1] , $aPDatas[t] , $aPDatas[t] );
                                                            break ;
                                                    case 'ng' :
                                                        $strHtmlBody .= sprintf( $PA[ng] , $aPDatas[ng_ln] ) ;
                                                            break ;
                                                    case 'n' :
                                                        $strHtmlBody .= sprintf( $PA[n] , $aPDatas[n_ln] ) ;
                                                            break ;
                                                    case 'sl':
                                                        $strHtmlBody .= $this->getSlection ( $aPDatas[m] , $PA[sl_head] , $PA[sl] , $PA[sl_end] ) ;
                                                        break ;
                                                    case 'i':
                                                   
                                                        $strHtmlBody .= sprintf( $PA , $aPDatas[qs] , $this->_var, $this->_prefix , $this->_postfix ) ;
                                                        break ;
                                            }
                                    }
                                    return $strHtmlBody ;
                            }
                    }
                    
            return '' ;
            }
            
            function getPage( $mixPage )
            {
                    if ( $this->_prefix )  $mixPage = str_replace( $this->_prefix  , '' , $mixPage ) ;
                    if ( $this->_postfix ) $mixPage = str_replace( $this->_postfix , '' , $mixPage ) ;
                    return intval( $mixPage ) ;
            }
            
            function setLink( $intPage )
            {
                    $strLink = $this->_qs ? '?' . $this->_qs . $this->_var . '=' . $this->_prefix . $intPage . $this->_postfix
                                               : '?' . $this->_var . '=' . $this->_prefix . $intPage . $this->_postfix ;
                    return $strLink ;
            }
            
            function getSlection ( $intMaxPage , $strSLHead , $strSL , $strSLEnd )
            {
                    $intThisPage = $this->getPage( $_REQUEST[$this->_var] ) ;
                        $intMax = intval ( $intMaxPage ) ;
                        if ($intMax < 1 )return;
                        for ( $i = 1 ; $i<= $intMax ; $i++ )
                        {
                        $strSLBODY .= sprintf( $strSL , $this->_qs , $this->_var , $this->_prefix ,  $this->_postfix , $i  ) ;
                        }
                        $strPattern = '/(\>' . $intThisPage . '<\/option>)/' ;
                        preg_match_all( $strPattern, $strSLBODY , $arrResult );
                        $strSLBODY = str_replace($arrResult[1][0]," selected ".$arrResult[1][0],$strSLBODY) ;
                        return $strSLHead . $strSLBODY . $strSLEnd  ;

            }
            
            function getQueryString( )
            {
                    $strPagepattern = '/('.$this->_var.'=('.$this->_prefix.')\d{0,}('.$this->_postfix.'))/' ;
                    preg_match_all( $strPagepattern, $_SERVER["QUERY_STRING"] , $arrResult );
                    $strQueryString = $arrResult[1][0] ? str_replace( "&".$arrResult[1][0] , "" , $_SERVER["QUERY_STRING"] ) : $_SERVER["QUERY_STRING"];
                    $strQueryString = str_replace( $arrResult[1][0] , "" , $strQueryString ) ;
                    if ( $strQueryString )
                    {
                            $strQueryString = $this->_encode ? htmlspecialchars($strQueryString).$this->_symbol : $strQueryString.$this->_symbol;
                    }
                    $this->_qs =  $strQueryString  ;
                    return true ;
            }
    }
}
?>

TOP

其实你叫AWEN

TOP

接着写 PHP cookie,session使用

cookie,session 是WEB应用程序保持用户状态的方法
cookie是保存的客户端的信息,由客户端连接服务器时发送到服务器的。
session是保存在服务端的信息,从这个角度session相对cookie更安全
当会话创建时服务器返回给客户端一个加密后的session id以标识用户身份,session id 一般保存在cookie当cookie不可用时由URL传递。

以下代码不可用,只是演示cookie session的使用.
复制内容到剪贴板
代码:

<?php   
// session start   
session_start(); // 开始一个会话,如果要使用session程序最前面一定要加上这句   
$_SESSION['user_id'] = '123';//给一个session 变量赋值,如果该变量不存在即创建   
  
echo $_SESSION['user_id'];//访问 session变量   
  
$_SESSION = array();//清空所有session变量   
  
session_destroy();//清除会话ID   
// session end   
  
// cookie start   
setcookie('user_id',123);//创建一个cookie变量user_id=123   
  
echo $_COOKIE['user_id'];//访问 cookie变量 和变通变量一样   
  
setcookie('user_id',0,time()-1);//删除cookie变量   
// codie end   
  
// 该代码不可运行,只是将所有使用方法在这里列出,实际应该不同功能在不同页面使用,将在下面的例子中演示   
?>  

TOP

发新话题