1.页面之间无法传递变量
get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_SESSION['foo']来得到。当然也可以修改自动全局变量为开(php.ini改为register_globals = On);考虑到兼容性,还是强迫自己熟悉新的写法比较好。
2.Win32下apache2 用get方法传递中文参数会出错
例如:test.php?a=你好&b=你也好
传递参数是会导致一个内部错误
解决办法:"test.php?a=".urlencode(你好)."&b=".urlencode(你也好)
urlencode($myname)主要用于正确识别汉字 空格以及其他特殊字符。
3.win32下的session不能正常工作
php.ini默认的session.save_path = /tmp 这显然是linux下的配置,win32下php无法读写session文件导致session无法使用,把它改成一个绝对路径就可以了,例如session.save_path = c:windows emp ,一般这个工作在配置php在win的安装环境的时候就应该解决的。
4.显示错误信息
当php.ini的display_errors = On并且error_reporting = E_ALL时,将显示所有的错误和提示,调试的时候最好打开以便纠错。
5.更改php.ini后没有变化
......
用PHP实现进度条效果。
<?php
set_time_limit(0);
echo '<h2>正在安装,请稍后...</h2>',
'<div style="border:1px solid #000;width:500px;"><div id="progress_bar">loading...</div></div>';
for($i=1;$i<=100;$i++){
$width = '500';
$width = ceil(($i/100)*$width);
echo '<mce:script type="text/javascript"><!--
',
'var progress_bar = document.getElementById("progress_bar");',
'progress_bar.style.background="#ff0000";',
'progress_bar.style.width ="'.$width.'px";',
"progress_bar.innerHTML = '{$i}%';",
'
// --></mce:script>';
sleep(1);
flush();
}
echo 'done';
?>
......
文件php.ini放入windows下,将下面内容拷贝到记事本命名为php.ini放入c:/windows下,重启Apache server:
[PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHP installations.
; By default, PHP installs itself with a configuration suitable for
; development purposes, and *NOT* for production purposes.
; For several security-oriented considerations that should be taken
; before going online with your site, please consult php.ini-recommended
; and http://php.net/manual/en/security.php.
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; This file controls many aspects of PHP's behavior. In order for PHP to
; read it, it must be named 'php.ini'. PHP looks for it in the current
; working directory, in the path designated by the environment variable
; PHPRC, and in the path that was defined in compile time (in that order).
; Under Windows, the compile-time path is the Windows directory. The
; path in which t ......
文件php.ini放入windows下,将下面内容拷贝到记事本命名为php.ini放入c:/windows下,重启Apache server:
[PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHP installations.
; By default, PHP installs itself with a configuration suitable for
; development purposes, and *NOT* for production purposes.
; For several security-oriented considerations that should be taken
; before going online with your site, please consult php.ini-recommended
; and http://php.net/manual/en/security.php.
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; This file controls many aspects of PHP's behavior. In order for PHP to
; read it, it must be named 'php.ini'. PHP looks for it in the current
; working directory, in the path designated by the environment variable
; PHPRC, and in the path that was defined in compile time (in that order).
; Under Windows, the compile-time path is the Windows directory. The
; path in which t ......
PHP的优点是简单实用。用它来写一些脚本,或者是webservice、数据库类的一些访问,确实是很简单方便。
但它有一个很大的问题,就是内存的回收问题。根据使用的经验觉得是几乎是没有回收。比如解析一个1百兆的XML文件,内存使用能到1G多,而且还不释放。
所以用php写后台程序,一定不要做成死循环的,至少是过一段时间退出一次,然后利用Shell脚本来做循环。
......
<?php
/**
* PHP100.com - 个人感觉非常简单,只要有点PHP基础滴人都应该能看懂~~
* Apache2 + PHP5.0
* Version:1.0
* 同时感谢PHP100所有的兄弟们
* ————————————————————————————————— Example —
* test.php @ 处理表单文件名
* <?php
*
* include("upload.php"); # 加入类文件
* $f_upload = new upload_other; # 创建对象
* $f_upload->set_file_type($_FILES['src']['type']); # 获得文件类型
* $f_upload->set_file_name($_FILES['src']['name']); # 获得文件名称
* $f_upload->set_file_size($_ ......
Session]
; 除非使用session_register()或$_SESSION注册了一个变量。
; 否则不管是否使用了session_start(),都不会自动添加任何session记录。
; 包括resource变量或有循环引用的对象包含指向自身的引用的对象,不能保存在会话中。
; register_globals指令会影响到会话变量的存储和恢复。
session.save_handler = "files"
; 存储和检索与会话关联的数据的处理器名字。默认为文件("files")。
; 如果想要使用自定义的处理器(如基于数据库的处理器),可用"user"。
; 有一个使用PostgreSQL的处理器:http://sourceforge.net/projects/phpform-ext/
session.save_path = "/tmp"
; 传递给存储处理器的参数。对于files处理器,此值是创建会话数据文件的路径。
; Windows下默认为临时文件夹路径。
; 你可以使用"N;[MODE;]/path"这样模式定义该路径(N是一个整数)。
; N表示使用N层深度的子目录,而不是将所有数据文件都保存在一个目录下。
; [MODE;]可选,必须使用8进制数,默认600(=384),表示每个目录下最多保存的会话文件数量。 ......