淡水河边整理的一些php的学习参考资料,方便大家学习php。如果想要查看tinybutstrong模板引擎的文章,请用tinybutstrong的标签查询。网上除了那个翻译不全的tbs中文手册,就只有淡水河边这里有一些小强(tinybutstrong)的中文参考资料了。都是淡水河边自己使用过程中摸索出来的,转载请保留链接。
» 阅读全文
Submitted by on 2006, August 21, 9:48 PM
淡水河边整理的一些php的学习参考资料,方便大家学习php。如果想要查看tinybutstrong模板引擎的文章,请用tinybutstrong的标签查询。网上除了那个翻译不全的tbs中文手册,就只有淡水河边这里有一些小强(tinybutstrong)的中文参考资料了。都是淡水河边自己使用过程中摸索出来的,转载请保留链接。
» 阅读全文
Submitted by on 2006, August 30, 10:21 PM
Submitted by on 2006, August 30, 4:30 AM
Submitted by on 2006, August 30, 4:18 AM
Submitted by on 2006, August 30, 4:16 AM
| 代码: |
| <?
//cookie.php if(!isset($flag)) { setcookie("mycookie","this my cookie!"); header("location:cookie.php?flag=1"); exit; } ?> <html> <body> <? echo "cookie中有:".$mycookie; ?> </body> </html> |
Submitted by on 2006, August 30, 3:53 AM
Submitted by on 2006, August 29, 11:31 PM
| 代码: |
| <?php
/* * 分页显示类 * PageItem.php v 1.0.2 * 说明: * 1. 配合MYSQL数据库使用 * 2. 类没有提供连接数据库的功能,需在外部建立数据库连接。 * */ /* * 使用方法: * $sql = "select * from news limit 0,10"; * $hdc = new PageItem($sql); * echo $hdc->myPageItem(); * $arrRecords = $hdc->ReadList(); * */ if (!defined("_BB_PAGEITEM_")) { define("_BB_PAGEITEM_", 1); } else return; class PageItem { var $iDefaultRecords = 10; // 默认每页显示记录数,如果没有设置,就使用默认值 var $iMaxRecord; //每页记录数 var $iTotal; //记录总数 var $sqlRecord; // 获取记录的SQL查询 var $iPages; //总页数 var $CPages; //当前页数 /* * 构造函数 -- 初始化变量 * 参数:SQL查询语句,将忽略LIMIT语句 * */ function PageItem($sql = "") { // register_shutdown_function($this->_PageItem()); if(!@mysql_ping()) { echo "本类需要在类外建立MySQL数据库连接"; exit; } /* * 解析SQL语句 * */ if ($sql <> "") { list($sql,$limit) = spliti("LIMIT", $sql); // 分析LIMIT语句,如果设置了,则以limit后面的记录为分页的记录数 list($cnt1,$cnt2) = explode(",",$limit); if(!empty($cnt2)) $this->SetMaxRecord($cnt2); elseif(!empty($cnt1)) $this->SetMaxRecord($cnt1); unset($cnt1); unset($cnt2); $this->sqlRecord = trim($sql); list(, $sql) = spliti("FROM", $sql); $sql = trim($sql); if(preg_match ("/\bGROUP\b \bBY\b/i", $sql)) { if(preg_match ("/\bHAVING\b/i", $sql)) list(,$field) = spliti("HAVING",$sql); list($field) = spliti(" ",trim($field)); $this->iTotal = $this->CountRecord("Select $field,COUNT(DISTINCT $field) AS cnt FROM " . $sql,2); } else $this->iTotal = $this->CountRecord("Select COUNT(*) AS cnt FROM " . $sql,1); } if($this->iMaxRecord<=0) $this->SetMaxRecord($this->iDefaultRecords); $this->iPages = ceil($this->iTotal / $this->iMaxRecord); $this->CPages = $_REQUEST["page"]; if ($this->CPages <= 0) $this->CPages = 1; if ($this->CPages > $this->iPages) $this->CPages = $this->iPages; } /* * 析构函数 -- 暂时不可用 * */ function _PageItem() { // $this->linkid = NULL; } function SetMaxRecord($cnt) { $this->iMaxRecord = $cnt; } /* * 统计匹配的记录总数 * */ function CountRecord($sql,$type) { if($type == 1) { if (($records = mysql_query($sql)) && ($record = mysql_fetch_assoc($records))) { return $record["cnt"]; } else return 0; } elseif($type == 2) { if($records = mysql_query($sql)) return mysql_affected_rows(); } } /* * 读取记录 * */ function GetRecord() { $ret = array(); $this->sqlRecord.=" LIMIT ".($this->CPages-1)*$this->iMaxRecord.",".$this->iMaxRecord; $records = mysql_query($this->sqlRecord); if(!$records) return; while($record = mysql_fetch_array($records)) { $ret[] = $record; } return $ret; } function LinktoPage($page, $msg) { $link = $this->PageUrl($page); return "<A href=\"$link\">$msg</A>\n"; } function PageUrl($page) { // 有些服务器设置的ServerName跟常用的不同,需要更改这里 $phpself = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]; $querystring = $_SERVER["QUERY_STRING"]; $querystring = preg_replace("/page=[0-9]*&?/i", "", $querystring); $link = $phpself . "?page=$page&" . $querystring; return $link; } /* * 显示当前页及总页数 * */ function PageNav() { echo "第" . $this->CPages . "页/共" . $this->iPages . "页"; } /* * 显示翻页按钮,包括首页、下页、上页、未页 * */ function PageButton() { if ($this->CPages > 1) { echo $this->LinktoPage(1, "首页"); echo " | "; echo $this->LinktoPage($this->CPages-1, "上一页"); } else { echo "首页 | 上一页"; } if ($this->CPages < $this->iPages) { echo " | "; echo $this->LinktoPage($this->CPages + 1, "下一页"); echo " | "; echo $this->LinktoPage($this->iPages, "首页"); } else { echo " | 下一页 | 尾页"; } } /* * 显示跳转页选择框 * */ function SelectItem() { echo "&nbsp;&nbsp;跳到第<Select name="topage" size="1" onchange="window.location=this.value">&nbsp;&nbsp;\n"; for($i = 1;$i <= $this->iPages;$i++) { if ($this->CPages == $i) $extra = "selected"; else $extra = ""; echo "<OPTION VALUE="" . $this->PageUrl($i) . "" $extra>$i</OPTION>"; } echo "</Select>\n"; } /* * 一次性显示所有按钮组件 * */ function myPageItem() { $this->PageButton(); $this->SelectItem(); $this->PageNav(); } } // 类结束 ?> |
| 代码: |
<? // db debug $time_start = getmicrotime(); @mysql_connect("localhost","root",""); //@mysql_select_db("cms"); //@mysql("create database testdb"); @mysql_select_db("testdb"); /* // 测试数据,请自行导入 Create DATABASE testdb; Create TABLE `testtable` ( `threadid` int(10) unsigned NOT NULL auto_increment, `title` varchar(250) NOT NULL default "", `lastpost` int(10) unsigned NOT NULL default "0", PRIMARY KEY (`threadid`) ) TYPE=MyISAM AUTO_INCREMENT=5142 ; # # 导出表中的数据 `testtable` # Insert INTO `testtable` VALUES (1, "用户手册", 1056675353); Insert INTO `testtable` VALUES (2, "斑竹守则", 1056208568); Insert INTO `testtable` VALUES (3, "Linux下构架邮件系统", 1056703118); Insert INTO `testtable` VALUES (4, "世界七大奇迹选举", 1029819163); Insert INTO `testtable` VALUES (5, "真的是寒冬耶~~~~", 1030512351); Insert INTO `testtable` VALUES (7, "[文章] PHP本地调试环境简易安装配置", 1032175589); Insert INTO `testtable` VALUES (8, "PHP还有希望么?", 1050675680); Insert INTO `testtable` VALUES (10, "[问题] oracle导入数据的权限问题?", 1032772383); Insert INTO `testtable` VALUES (17, "vBulletin 2.2.9版本发布了", 1040229341); Insert INTO `testtable` VALUES (11, "[文章] Web服务器解决方案(一)", 1036405968); Insert INTO `testtable` VALUES (12, "Tomcat启动不了?", 1036662305); Insert INTO `testtable` VALUES (13, "程序员不得不看的好帖(转)", 1085021674); Insert INTO `testtable` VALUES (14, "本站的FTP站点开通,欢迎大家使用!", 1084408733); Insert INTO `testtable` VALUES (15, "现在如何登陆阿?", 1037956765); Insert INTO `testtable` VALUES (16, "[分享] 可以和你做一个联接么", 1037785003); Insert INTO `testtable` VALUES (18, "FTP目录在调整中...", 1037869139); Insert INTO `testtable` VALUES (19, "能开放ftp吗?", 1039633468); Insert INTO `testtable` VALUES (20, "FTP综合论坛的访问问题解决了", 1037949721); Insert INTO `testtable` VALUES (21, "请问斑竹那个*.gho文件用什么程序打开? 谢谢!!!", 1082483109); Insert INTO `testtable` VALUES (22, "有没有找不到的软件呢?", 1039633312); Insert INTO `testtable` VALUES (23, "互联网论坛:中国互联网 盈利别得意", 1039633657); Insert INTO `testtable` VALUES (24, "最厉害的图片!", 1039633215); Insert INTO `testtable` VALUES (25, "论坛银行", 1060911818); Insert INTO `testtable` VALUES (36, "人生到底为了什么呢?", 1039764753); Insert INTO `testtable` VALUES (35, "关于五个创业者的五个细节", 1039748528); Insert INTO `testtable` VALUES (28, "修改论坛显示发表信息的修改", 1039628337); Insert INTO `testtable` VALUES (29, "Oracle与DB2比较", 1039633786); Insert INTO `testtable` VALUES (31, "PHP 4.3.0最后一个预发行版本", 1040815970); Insert INTO `testtable` VALUES (40, "FTP站点开通音乐频道", 1040399193); Insert INTO `testtable` VALUES (37, "平均拥有21个密码 IT用户的密码泛滥成灾 [转贴]", 1039772963); Insert INTO `testtable` VALUES (38, "我要软件啊", 1042300012); Insert INTO `testtable` VALUES (39, "这里的速度相对别的FTP来说(对我而言)是最快的了", 1039947371); Insert INTO `testtable` VALUES (41, "[文章] Web服务器解决方案(一)", 1040027122); Insert INTO `testtable` VALUES (42, "那位大哥哥原帮忙?", 1040229203); Insert INTO `testtable` VALUES (43, "老大请进 有问题求教", 1040399120); Insert INTO `testtable` VALUES (44, "老大 怎么回事", 1040228529); Insert INTO `testtable` VALUES (45, "Oracle中Delete时候提示出错:ORA-02292", 1040399794); Insert INTO `testtable` VALUES (46, "如何连同email地址也复制过去?", 1040399557); Insert INTO `testtable` VALUES (47, "星矢冥王篇和字幕", 1044628632); Insert INTO `testtable` VALUES (48, "无间道主题曲和一经典", 1040724634); Insert INTO `testtable` VALUES (49, "要霸王别姬吗", 1040526751); Insert INTO `testtable` VALUES (50, "双城记", 1040646014); Insert INTO `testtable` VALUES (51, "第四集有了 马上放上去", 1040566962); Insert INTO `testtable` VALUES (52, "这个地方好象不合适偶来", 1046516491); Insert INTO `testtable` VALUES (53, "PHP4中文教程", 1040568390); Insert INTO `testtable` VALUES (54, "FTP有问题了吗", 1040724674); Insert INTO `testtable` VALUES (55, "奇怪,怎么就两个人呢?", 1040996101); Insert INTO `testtable` VALUES (56, "有没有PHP/GTK的详细教程啊??", 1040700746); Insert INTO `testtable` VALUES (58, "论坛如何调整", 1042116789); Insert INTO `testtable` VALUES (57, "哪儿有PHPCompiler下载啊?", 1040713790); Insert INTO `testtable` VALUES (59, "MySQL错误(errno: 140)错误的解决", 1040983562); Insert INTO `testtable` VALUES (60, "加油?灌水?", 1042198274); Insert INTO `testtable` VALUES (61, "PHP 4.3.0 正式发行了", 1041107823); Insert INTO `testtable` VALUES (62, "伯恩的身份 强烈推荐 下面这篇介绍是转载", 1042300019); Insert INTO `testtable` VALUES (63, "老大 有红磨房", 1042944938); Insert INTO `testtable` VALUES (64, "haha", 1042300076); Insert INTO `testtable` VALUES (65, "老大 又在调整吗", 1041672910); Insert INTO `testtable` VALUES (66, "学习PHP", 1042560221); Insert INTO `testtable` VALUES (67, "php+oracle 中文显示不正常", 1052969974); Insert INTO `testtable` VALUES (68, "老大 怎么了", 1042301133); Insert INTO `testtable` VALUES (69, "倒 不知不觉变斑竹拉", 1042300340); Insert INTO `testtable` VALUES (72, "PHP网站该往何处去?", 1045971230); Insert INTO `testtable` VALUES (70, "伯恩的身份 老大删了吗", 1042301209); Insert INTO `testtable` VALUES (71, "美国电影协会评选出的美国历史上的最伟大的100部电影(转)", 1043059704); Insert INTO `testtable` VALUES (73, "THE TWO TOWERS", 1042715292); Insert INTO `testtable` VALUES (75, "[重要] 目的是方便PHP爱好者", 1043287064); Insert INTO `testtable` VALUES (76, "好文章 大家来看看 (转)", 1042649914); Insert INTO `testtable` VALUES (77, "忠奸人", 1042945061); Insert INTO `testtable` VALUES (78, "电影点播", 1079154880); Insert INTO `testtable` VALUES (79, "2001-2002日本动漫排名", 1052491517); Insert INTO `testtable` VALUES (80, "关于论坛改版得通知", 1048655501); Insert INTO `testtable` VALUES (81, "[转贴] 我的购盘经验", 1043226808); Insert INTO `testtable` VALUES (82, "&lt;hero&gt;已上传完毕", 1043246593); Insert INTO `testtable` VALUES (83, "最新电影 BLOOD WORK", 1043246292); Insert INTO `testtable` VALUES (84, "感谢djzhi", 1043923465); Insert INTO `testtable` VALUES (85, "Blood Work 上传完", 1043582674); Insert INTO `testtable` VALUES (86, "[求助]PHP安装", 1043685944); Insert INTO `testtable` VALUES (87, "[转贴] 我的一个朋友与我谈到当前中国人的生活方式", 1043678405); Insert INTO `testtable` VALUES (88, "现在服务器陷入非常缓慢的状态", 1043686177); Insert INTO `testtable` VALUES (89, "提请新注册用户注意!", 1051885362); Insert INTO `testtable` VALUES (91, "能上传了吗", 1044886700); Insert INTO `testtable` VALUES (90, "请问:我用$_session[var]去获得session中的变量,有时可以有时不行?", 1078180091); Insert INTO `testtable` VALUES (92, "[求助]", 1051454294); Insert INTO `testtable` VALUES (93, "祝大家新春愉快", 1044707042); Insert INTO `testtable` VALUES (94, "紧急求助", 1044271917); Insert INTO `testtable` VALUES (95, "[转贴] 面试工作比找“女朋友”要烦啊!", 1043935699); Insert INTO `testtable` VALUES (96, "再次求助", 1044334208); Insert INTO `testtable` VALUES (97, "菜鸟紧急求助!", 1044283078); Insert INTO `testtable` VALUES (98, "超级菜鸟求助!!!!!!!!!!!", 1044464729); Insert INTO `testtable` VALUES (99, "进一步求助。", 1044462787); Insert INTO `testtable` VALUES (100, "如何以模块化的方式在Apache下安装PHP", 1078811867); */ include("./PageItem.php"); $pi = new PageItem("select * from testtable"); echo "<html><head>\n"; echo "<head><meta http-equiv="content-type" content="text/html;charset=gb2312">\n<title>类使用示例--Boban@21php.com</title></head>"; echo "<body>"; echo "<p align=center style="font-size:9pt">PHP服务器系统:".PHP_OS."<br>"; echo "<br<br>"; $records = $pi->getrecord(); if(is_array($records)) { while(list($key,$val)=each($records)) { echo $val["threadid"].":".$val["title"]."(".date("Y-m-d",$val["lastpost"]).")<br>\n";; } } echo "<br<br>"; $pi->myPageItem(); //$charset = mysql_client_encoding($auth->bb_db_conn); //printf ("current character set is %s\n", $charset); ?> <? echo "</body></html>"; $time_end = getmicrotime(); printf("<br>{程序执行时间: %0.3f 秒}</p>\n",$time_end - $time_start); function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } ?> |
Submitted by on 2006, August 29, 3:57 AM
Submitted by on 2006, August 27, 1:22 PM
| 代码: |
session_start(); if(isset($HTTP_COOKIE_VARS["PHPSESSID"])) //如果有cookie变量PHPSESSIN { session_id($HTTP_COOKIE_VARS["PHPSESSID"]); //取出PHPSESSID(就是session id),和服务器上对应的session建立连接 $PHPSESSID=$HTTP_COOKIE_VARS["PHPSESSID"]; } else $PHPSESSID=session_id(); //如果没有就重新生产一个新的session id setcookie("PHPSESSID",$PHPSESSID,time()+3600*2400,$cookie_path); //设cookie,保存session id if($HTTP_GET_VARS["islogout"]!=1 && isset($HTTP_POST_VARS["name"])) //如果用户没有注销,并且存在由表单提交过来的用户名 { $HTTP_SESSION_VARS["account"]="guest"; //先把session变量account,也就是当前已经登录的用户名冲掉(这点我现在觉得不好),变成guest $HTTP_SESSION_VARS["isadm"]=0; //也是清掉,isadm是我这个程序表示是否为管理员的变量 $HTTP_SESSION_VARS["style"]=$HTTP_GET_VARS["style"]; //style是我的程序中表示当前用户的样式,也就是模板 $query="select * from ka_account where account="".$HTTP_POST_VARS["name"]."";"; $result=mysql_query($query); //从数据库中取出该用户名的密码等信息 if(mysql_num_rows($result)==1) //如果找到一个匹配的 { $rec=mysql_fetch_object($result); if($rec->banned!=1){ //如果用户没有被禁止 if(encrypt($HTTP_POST_VARS["passwd"])==$rec->passwd) //如果密码匹配,encrypt是我的加密函数,我使用了默认的md5 { $HTTP_SESSION_VARS["account"]=$rec->account; //设当session变量account为这个用户 $HTTP_SESSION_VARS["isadm"]=$rec->isadm; //类似上面 $err="已登录"; } else $err="密码错误"; } else $err="账号被禁止"; } else $err="账号不存在"; } if($HTTP_GET_VARS["islogout"]==1) //如果用户在注销,就把所有的session变量设置成guest的 { $HTTP_SESSION_VARS["account"]="guest"; $HTTP_SESSION_VARS["isadm"]=0; $HTTP_SESSION_VARS["style"]="default"; } echo $err; 显示出错信息 |
Submitted by on 2006, August 27, 1:16 PM
| 代码: |
<?php /*-----------------------------分页操作类------------------------------- 1.操作灵活,方便mvc模式开发者 2.本代码只用于交流 3.应用实例: $sqlStr="select count(*) from news"; $query=mysql_query($sqlStr,$conn); $data_sum=@mysql_result($query,0); $sqlStr="select * from news order by id"; $page=new page($data_sum,5); $page->execute($sqlStr); echo $page->show_item("#FF0000",5)."<br>"; $array=$page->show(true); ----------------------------------------------------------------------*/ class page{ var $page_size; //显示数据的行数(可提供,可设置) var $data_sum; //查询数据的总数(需提供) var $page_sum; //页面总数 var $page=0; //当前页 var $html_href_up; //上一页的连接herf值 var $html_href_next; //下一页的连接herf值 var $html_href_start; //第一页的连接herf值 var $html_href_end; //尾页的连接herf值 var $page_url_request="page"; //页面请求(url)的分页参数值,例如:http://localhost/index.php... function page($data_sum,$page_size=10){ $this->data_sum=$data_sum; $this->page=($_REQUEST[$this->page_url_request]!="")? $_REQUEST[$this->page_url_request]: 1; $this->page_size=$page_size; $this->page_sum(); } /*------------------------------引用$sqlStr进行操作----------------------------- 参数为SQL语句的引用 ------------------------------------------------------------------------------*/ function execute(& $sqlStr){ if($sqlStr=="") $this->halt("请先设置\$sqlStr的值!"); $limit1=($this->page-1) * $this->page_size; $limit2=$limit1+$this->page_size; $limit_mod=" limit ".$limit1.",".$limit2." "; if(eregi("limit",$sqlStr)){ $mod="/limit(\s)+[0-9]+(,(\s)*[0-9]*)?/i"; $sqlStr=preg_replace($mod,$limit_mod,$sqlStr); } else $sqlStr .=$limit_mod; } /*----------------------------页面计算--------------------------------------*/ function page_sum(){ $page_end=$this->data_sum%$this->page_size; $page_sum=(int) ($this->data_sum/$this->page_size); $this->page_sum=($page_end==0)?$page_sum:$page_sum+1; } /*---------------------------跳转连接操作----------------------------------*/ function href($page){ if($page>$this->page_sum || $this->data_sum==0 || $this->page_sum<=1) return "#"; else{ $request_string=$_SERVER["QUERY_STRING"]; if(eregi($this->page_url_request,$request_string)){ $mod="/$this->page_url_request=[0-9]+/"; eval("\$mod=\"$mod\";"); $request_string=preg_replace($mod,$this->page_url_request."=".$page,$request_string); } else $request_string.="&".$this->page_url_request."=".$page; return "http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$request_string; } } /*---------------------------------返回跳转连接的herf------------------------------ 可单个返回引用,或者返回索引数组;返回数组需提供一个任意值的 ---------------------------------------------------------------------------------*/ function show($return_type=false){ $this->html_href_up=($this->page<=1)?"#":$this->href($this->page-1); $this->html_href_next=$this->href($this->page+1); $this->html_href_start=$this->href(1); $this->html_href_end=$this->href($this->page_sum); if($return_type!=false) return array("up"=>$this->html_href_up,"next"=>$this->html_href_next,"start"=>$this->html_href_start,"end"=>$this->html_href_end); } /*-------------------------返回联系跳转的html---------------------------- 可提供当前页的值的显示颜色 可设置显示大小 例如:1 2 3 4 5 6 7 ------------------------------------------------------------------------*/ function show_item($index_color="#FF0000",$item=9){ $page=$this->page; $midd=(int) ($item/2); if($this->page_sum<=$item){ //如果总页数大于显示的页数时, $show_start=1; $show_end=$this->page_sum; }elseif($page-$midd <= 0){ $show_start=1; $show_end=$item; } elseif($page+($item-$midd)>=$this->page_sum){ $show_start=$this->page_sum-$item+1; $show_end=$this->page_sum; } else{ $show_start=$page-$midd; $show_end=$page+($item-$midd)-1; } for($i=$show_start;$i<=$show_end;$i++){ $item_son=($i==$this->page)?"<font color=".$index_color."><strong>".$i."</strong></font>":$i; $item_html.="<a href=".$this->href($i).">".$item_son."</a>&nbsp;"; } return "&nbsp;".$item_html; } /* ------------------------------显示错误----------------------------*/ function halt($errorStr){ echo "<p><font color=\"#FF0000\"><strong>错误提示:</strong></font></p>"; echo "<p>&nbsp;&nbsp;&nbsp;&nbsp;".$errorStr."</p>"; exit(); } } ?> |