浏览模式: 标准 | 列表全部文章

[置顶] 本站php相关整理资料集合

淡水河边整理的一些php的学习参考资料,方便大家学习php。如果想要查看tinybutstrong模板引擎的文章,请用tinybutstrong的标签查询。网上除了那个翻译不全的tbs中文手册,就只有淡水河边这里有一些小强(tinybutstrong)的中文参考资料了。都是淡水河边自己使用过程中摸索出来的,转载请保留链接。

» 阅读全文

Tags: 编程标准, 手册, tinybutstrong, div, css

codeigniter里管理页面框架的使用

控制器代码:

PHP代码
  1. class Admin extents Control  
  2. {  
  3.     function index() {  
  4.         $this->load->view('admin/index');  
  5.     }  
  6.     function top() {  
  7.         $this->load->view('admin/top');  
  8.     }  
  9.     function menu() {  
  10.         $this->load->view('admin/menu');  
  11.     }  
  12.     function main() {  
  13.         $this->load->view('admin/main');  
  14.     }  
  15.     function bottom() {  
  16.         $this->load->view('admin/bottom');  
  17.     }  
  18. }  

views文件夹下有个专门的admin文件夹,里面都是管理页面(index.php , top.php , menu.php , main.php , bottom.php)

index.php内容如下:

 

XML/HTML代码
  1. <html><head><title> Administrator’s control panel</title>
  2. </head>  
  3. <frameset rows="60,*,27" frameborder="no" border="0" framespacing="0">  
  4.   <frame src="<?php echo site_url("Admin/top") ?>" name="topFrame" scrolling="no">  
  5.   <frameset rows="*" cols="0,*" name="ecc" framespacing="0" frameborder="no" border="0">  
  6.     <frame src="<?php echo site_url("Admin/menu") ?>" name="mainFrame" border="0" scrolling="no">  
  7.     <frame src="<?php echo site_url("Admin/main") ?>" name="rightFrame" scrolling="auto">  
  8.   </frameset>  
  9.   <frame src="<?php echo site_url("Admin/bottom") ?>" name="bottomFrame" scrolling="no">  
  10. </frameset>  
  11. </html>  

 

Tags: codeigniter

[转载]PHP header函数用法 Tips

1。PHP header() 函数

网上很多资料这样写:php的函数header()可以向浏览器发送Status标头,如 header(”Status: 404 Not Found”)。

但是我发现实际上浏览器返回的响应却是:

HTTP/1.x 200 OK
Date: Thu, 03 Aug 2006 07:49:11 GMT
Server: Apache/2.0.55 (Win32) PHP/5.0.5
X-Powered-By: PHP/5.0.5
Status: 404 Not Found
Content-Length: 0
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: text/html

查了一些资料,正确的写法是:
header(”http/1.1 404 Not Found”);

第一部分为HTTP协议的版本(HTTP-Version);第二部分为状态代码(Status);第三部分为原因短语(Reason-Phrase)。

若要想让浏览器不是从 Proxy 或 cache 中取得页面,可以使用下列的标头

header(”Expires: Mon, 26 Jul 1997 05:00:00 GMT”);
header(”Last-Modified: ” . gmdate(”D, d M Y H:i:s”) . “GMT”);
header(”Cache-Control: no-cache, must-revalidate”);
header(”Pragma: no-cache”);

具体含义下面解释。

2。禁止页面在IE中缓存

http响应消息头部设置:

CacheControl = no-cache
Pragma=no-cache
Expires = -1

Expires是个好东东,如果服务器上的网页经常变化,就把它设置为-1,表示立即过期。如果一个网页每天凌晨1点更新,可以把Expires设置为第二天的凌晨1点。

当HTTP1.1服务器指定CacheControl = no-cache时,浏览器就不会缓存该网页。

旧式 HTTP 1.0 服务器不能使用 Cache-Control 标题。所以为了向后兼容 HTTP 1.0 服务器,IE使用Pragma:no-cache 标题对 HTTP 提供特殊支持。如果客户端通过安全连接 (https://) 与服务器通讯,且服务器在响应中返回 Pragma:no-cache 标题,则 Internet Explorer 不会缓存此响应。注意:Pragma:no-cache 仅当在安全连接中使用时才防止缓存,如果在非安全页中使用,处理方式与 Expires:-1 相同,该页将被缓存,但被标记为立即过期。

http-equiv meta标记:

在html页面中可以用http-equiv meta来标记指定的http消息头部。老版本的IE可能不支持html meta标记,所以最好使用http消息头部来禁用缓存。

3。隐藏文件的位置

html标签 就可以实现普通文件下载。如果为了保密文件,就不能把文件链接告诉别人,可以用header函数实现文件下载。

header(”Content-type: audio/mpeg”);
header(”Content-Disposition: attachment; filename=filenale”);
header(”Content-Description: PHP3 Generated Data”);

4。header函数前输入内容

一般来说在header函数前不能输出html内容,类似的还有setcookie() 和 session 函数,这些函数需要在输出流中增加消息头部信息。如果在header()执行之前有echo等语句,当后面遇到header()时,就会报出 “Warning: Cannot modify header information - headers already sent by ….”错误。就是说在这些函数的前面不能有任何文字、空行、回车等,而且最好在header()函数后加上exit()函数。例如下面的错误写法,在两个php代码段之间有一个空行:

//some code here
?>
//这里应该是一个空行
header(”http/1.1 403 Forbidden”);
exit();
?>

原因是:PHP脚本开始执行 时,它可以同时发送http消息头部(标题)信息和主体信息. http消息头部(来自 header() 或 SetCookie() 函数)并不会立即发送,相反,它被保存到一个列表中. 这样就可以允许你修改标题信息,包括缺省的标题(例如 Content-Type 标题).但是,一旦脚本发送了任何非标题的输出(例如,使用 HTML 或 print() 调用),那么PHP就必须先发送完所有的Header,然后终止 HTTP header.而后继续发送主体数据.从这时开始,任何添加或修改Header信息的试图都是不允许的,并会发送上述的错误消息之一。

解决办法:

修改php.ini打开缓存(output_buffering),或者在程序中使用缓存函数ob_start(),ob_end_flush()等。原理是:output_buffering被启用时,在脚本发送输出时,PHP并不发送HTTP header。相反,它将此输出通过管道(pipe)输入到动态增加的缓存中(只能在PHP 4.0中使用,它具有中央化的输出机制)。你仍然可以修改/添加header,或者设置cookie,因为header实际上并没有发送。当全部脚本终止时,PHP将自动发送HTTP header到浏览器,然后再发送输出缓冲中的内容。

Tags: header

简介在PHP中采用MVC分离的设计方法

为了更好的演示MVC的工作方式,我们使用了一个简单的新闻文章发布系统作为例子.分为使用MVC和不使用MVC两种方式.
我们只作一个基本的演示,从数据库里读出一些文章列表,并在页面上显示。一般的流程就是,连接数据库,查询数据库,循环输出html结果。下面的代码就是如此做的。(淡水感觉怪怪的,语言组织得不好。好在代码比较容易理解)

PHP代码
  1. <?php   
  2. mysql_connect(...);   
  3. $result = mysql_query('select * from news order by article_date desc');   
  4. ?>   
  5. <html>   
  6.     <body>   
  7.         <h1>News Articles</h1>         
  8.       <?php while ($row = mysql_fetch_object($result)) { ?>   
  9.                 <h2><?php echo $row->headline ?></h2>              
  10.                 <p>   
  11.                     <?php echo $row->body ?>   
  12.                 </p>   
  13.       <?php } ?>   
  14.     </body>   
  15. </html>  

采用mvc方式.

model:

PHP代码
  1. <?php      
  2. function get_articles()   
  3. {   
  4.     mysql_connect(...);    
  5.     $result = mysql_query('select * from news order by article_date desc');    
  6.     $articles = array();   
  7.     while ($row = mysql_fetch_objects($result)) {   
  8.         $articles[] = $row;    
  9.     }   
  10. return $articles;   
  11. }   
  12. ?>  

controller:

PHP代码
  1. <?php   
  2. $articles = get_articles();    
  3. display_template('articles.tpl');   
  4. ?>  

view:

PHP代码
  1. <html>   
  2. <body>   
  3. <h1>News Articles</h1>   
  4.         <?php foreach ($articles as $row) { ?>   
  5.         <h2><?php echo $row->headline ?></h2>              
  6.             <p>   
  7.                 <?php echo $row->body ?>   
  8.             </p>           
  9.         <?php } ?>     
  10. </body>   
  11. </html>  

译得不好请多多包涵.原文:http://reinholdweber.com/?p=16

Tags: mvc

CSS hack:区分IE6,IE7,firefox

区别IE6FF

       background:orange;*background:blue;

区别IE6IE7
       background:green !important;background:blue;

区别IE7与FF:
        background:orange*background:green;

区别FFIE7IE6
        background:orange;*background:green !important;*background:blue;

注:IE都能识别*;标准浏览器(如FF)不能识别*; IE6能识别*,但不能识别 !important, IE7能识别*,也能识别!important; FF不能识别*,但能识别!important

  IE6 IE7 FF
* ×
!important ×

另外再补充一个,下划线"_",
IE6支持下划线,IE7和firefox均不支持下划线。(推荐)

于是大家还可以这样来区分IE6IE7firefox
: background:orange;*background:green;_background:blue;

注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。

转自:http://www.zvv.cn/blog/

Tags: css

忙碌,作品,反省,思考

近来职务调动,专心写php的时间少了很多。

www.gpsnet.cc 刚刚做好的。

大部分采用原生的html。
"申请加入" 和 "留言" 采用了php发送到邮箱里。
新闻方面未作。
采用了jQuery,在填写表单时改善了一点点用户体验。

很少反省自己,没时间,也不愿多想。无他,活得太窝囊了些。

Tags: 作品

include的另类用法

include()时,如果被包含文件使用了return返回值,那么include()就直接返回该return的值。

PHP代码
  1. <?php   
  2. //1.php   
  3. return 'hello world';   
  4. ?>  
PHP代码
  1. <?php   
  2. //2.php   
  3. $str = include '1.php';   
  4. echo "$str"//输出hello world   
  5. ?>   

利用这个特性可以方便地使用php文件来做配置。比如

PHP代码
  1. <?php   
  2. //config.php   
  3. return array(   
  4.             'db'=>array(   
  5.             'host' => 'localhost',   
  6.             'user' => 'root',   
  7.             'password' => 'root',   
  8.             'name' => 'test',   
  9.             'encoding' => 'utf8'  
  10.     )   
  11. );   

使用时只要 $config = include 'inc/config.php'; 避免了不必要的变量,节省内存.

另:

今天用editplus时,发现“函数列表”里空空的。原来是function前面有public等限定符。

把php的函数模板改动一下就认识了。

PHP代码
  1. ^[ \t]*(function|public|protected|private|static)[ \t].*\([^;]*$  

Tags: include, editplus

jQuery获取表单各元素的值及其AJAX应用

jQuery获取表单各元素的值及其AJAX应用.比较简单也是常用到的.

» 阅读全文

Tags: jquery

PATH_INFO方法实现页面伪静态的函数

先贴代码

PHP代码
  1. <?php      
  2. /*函数url_parse用于解析url,使用时需要在前面定义    
  3. *define('PATH_INFO',true);      
  4. *需要解析时调用该函数,取值方法用回$_GET['xxx']即可      
  5. */     
  6. function url_parse()      
  7. {      
  8.     if (!(isset($_SERVER['PATH_INFO']) && defined('PATH_INFO'))) {      
  9.         return;      
  10.     }      
  11.     $url = substr($_SERVER['PATH_INFO'], 1);      
  12.     $url = str_replace(array("'", '"', '.htm', '.html'), array('', '', '', ''), $url);    
  13.     $url = explode('/', $url);      
  14.     $param_count = count($url);      
  15.     for ($i = 0; $i < $param_count$i += 2) {      
  16.         if (isset($url[$i + 1]) && !is_numeric($url[$i])) {      
  17.             $_GET[$url[$i]] = $url[$i + 1];      
  18.         }      
  19.     }      
  20.     unset($param_count$url$i);      
  21. }      
  22. ?>  

 

说明:

www.yogool.cn/index.php/category/ajax 。(ajax后面可加.htm)这样,用$_GET['category']即可取出ajax.

再如 www.yogool.cn/index.php/category/ajax/page/2.htm,这样用$_GET['page']可取到2;它的页面相当于www.yogool.cn/index.php?category=ajax&page=2

淡水以前也写过,不过不是没写成函数,且要考虑到图片和css路径的问题.

原文:http://www.yogool.cn/index.php?controller=Default&action=ShowArticle&aid=10

更新一下:

 

PHP代码
  1. <?php   
  2.   
  3.   
  4. /*函数url_parse用于解析url,使用时需要在前面定义  
  5. *define('PATH_INFO',true);  
  6. *需要解析时调用该函数,取值方法用回$_GET['xxx']即可  
  7. */  
  8. function url_parse() {   
  9.     if (!(isset ($_SERVER['PATH_INFO']) && defined('PATH_INFO'))) {   
  10.         return;   
  11.     }   
  12.     $urlsubstr($_SERVER['PATH_INFO'], 1);   
  13.     $urlstr_replace(array (   
  14.         "'",   
  15.         '"',  
  16.         '.html',  
  17.         '.htm'  
  18.     ), array (  
  19.         '',  
  20.         '',  
  21.         '',  
  22.         ''  
  23.     ), $url);  
  24.     $url= explode('/', $url);  
  25.     $param_count= count($url);  
  26.     for ($i= 0; $i < $param_count; $i += 2) {  
  27.         if (isset ($url[$i +1]) && !is_numeric($url[$i])) {  
  28.             $_GET[$url[$i]]= $url[$i +1];  
  29.         }  
  30.     }  
  31.     unset ($param_count, $url, $i);  
  32. }  
  33. define('PATH_INFO', true);  
  34. url_parse();  
  35. header("Content-type:text/html;charset=utf-8");  
  36. echo "urlencode:";  
  37. echo urlencode($_GET['class']) . ',' . $_GET['news'];  
  38. echo '<br />urldecode:';  
  39. echo urldecode($_GET['class']) . ',' . $_GET['news'];  
  40. echo '<br />';  
  41. echo '<img src="/Public/Images/display.png" />';  
  42. echo '<br />';  
  43. echo '<a href="http://localhost/test.php/class/淡水/news/100.html">my link1</a>';   
  44. echo '<hr />';  
  45. echo '<a href="http://localhost/test.php/class/' . urlencode('淡水') . '/news/100.html">my link2</a>';   
  46. echo '<hr />';  
  47. echo '<a href="http://localhost/test.php?class=淡水&news=100">my link3</a>';   
  48. ?>  

注意点:原文代码里html在htm后面,这样地址为xxx.html的时候,会有一个L没替换到。

直接输入:http://localhost/test.php?class=淡水&news=100 中文会有乱码,点击连接却不会。其它都正常。怪事?!!!

Tags: path_info

30分钟搞定jQuery(E文)

内容: 

内容:

  1. jQuery特点
  2. CSS选择器用法
  3. jQuery集合
  4. jQuery集合操作
  5. 获取匹配元素的值
  6. DOM元素遍历
  7. 事件处理
  8. 安静加载运行
  9. 对象链串访问
  10. 疯狂链串(Crazy Chaining)
  11. Ajax用法
  12. 推荐了几个插件

 

Tags: jquery

Records:64912345678910»