CKFinder上传中文名文件乱码问题的解决方法(PHP)

上传中文名文件乱码问题

在ckfinder/config.php中找到如下一段配置代码:

 

/*
If you have iconv enabled (visit http://php.net/iconv for more information),
you can use this directive to specify the encoding of file names in your
system. Acceptable values can be found at:
 http://www.gnu.org/software/libiconv/

Examples:
 $config['FilesystemEncoding'] = 'CP1250';
 $config['FilesystemEncoding'] = 'ISO-8859-2';
*/
$config['FilesystemEncoding'] = 'UTF-8';

将UTF-8修改为GB2312,上传后文件名正确了,但在CKEditor中显示的链接出现乱码,因为CKEditor所在页面使用的字符集是UTF-8,未去细究如何解决这个问题,采用了文件重命名的方案去替代解决。

上传文件重命名

修改ckfinder\core\connector\php\php5\CommandHandler\FileUpload.php

找到以下代码

if ($sFileName != $sUnsafeFileName) {
  $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
}

在这段代码之后添加

$sExtension=CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
$sFileName=date('YmdHis').'.'.$sExtension;

参考来源:http://witmax.cn/ckfinder-rename-file.html

PHP:Deprecated: Function set_magic_quotes_runtime() is deprecated 错误的解决方法

在安装PHPCMS出现Deprecated: Function set_magic_quotes_runtime() is deprecated 错误,查了一下网络及资料发现是PHP5.3和PHP6.0之后移除了set_magic_quotes_runtime()函数。

 

set_magic_quotes_runtime(0)函数作用解释
在php.ini的配置文件中,有个布尔值的设置,就是magic_quotes_runtime,当它打开时,php的大部分函数自动的给从外部引入的(包括数据库或者文件)数据中的溢出字符加上反斜线。

当然如果重复给溢出字符加反斜线,那么字符串中就会有多个反斜线,所以这时就要用set_magic_quotes_runtime()与get_magic_quotes_runtime()设置和检测php.ini文件中magic_quotes_runtime状态。

为了使自己的程序不管服务器是什么设置都能正常执行。可以在程序开始用get_magic_quotes_runtime检测设置状态秋决定是否要手工处理,或者在开始(或不需要自动转义的时候)用set_magic_quotes_runtime(0)关掉。

magic_quotes_gpc设置是否自动为GPC(get,post,cookie)传来的数据中的'"/加上反斜线。可以用get_magic_quotes_gpc()检测系统设置。如果没有打开这项设置,可以使用addslashes()函数添加,它的功能就是给数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号(')、双引号(")、反斜线(/)与 NUL(NULL 字符)。

解决办法:

//@set_magic_quotes_runtime(0);
ini_set("magic_quotes_runtime",0);

就是用ini_set()办法替代原有的set_magic_quotes_runtime语法。

来源地址:http://blog.csdn.net/nstwolf/article/details/5806616

发生这个错误是有一位客户使用一个非主流的CMS产品建站。该产品叫IN67企业网站管理系统。该系统目前最新版本是2.0版,发布时间是2011年7月25日。因此估计该客户的网站是上一个版本的程序。不过目前在IN67官网上找不到上一个版本的下载链接了。

两款PHP环境搭建工具

 学习、使用PHP的前提是要配置好PHP环境。windows用户最麻烦的也是环境配置。于是,这类型的集成工具就诞生了。

1、XAMPP 下载地址:http://www.apachefriends.org/zh_cn/xampp.html 这款貌似是德国人开发的。不过是多语言版,支持中文良好。

2、PHPNow 下载地址:http://phpnow.org/ 这款貌似是中国人开发的。只有中文版。

值得一提的是,由于是集成环境套件,只支持本地访问,也就是说,只能在本地使用。即使你架设好网站,其他人是无法浏览你的网站的,局域网也不行。 想要支持远程,只能自己配制一下apache或者iis了。

PHP双冒号::的用法

双冒号操作符即作用域限定操作符Scope Resolution Operator可以访问静态、const和类中重写的属性与方法。

在类定义外使用的话,使用类名调用。在PHP 5.3.0,可以使用变量代替类名。

Program List:用变量在类定义外部访问

    
<?php
class Fruit {
    const CONST_VALUE = 'Fruit Color';
}

$classname = 'Fruit';
echo $classname::CONST_VALUE; // As of PHP 5.3.0

echo Fruit::CONST_VALUE;
?>

Program List:在类定义外部使用::

  
<?php
class Fruit {
    const CONST_VALUE = 'Fruit Color';
}

class Apple extends Fruit
{
    public static $color = 'Red';

    public static function doubleColon() {
        echo parent::CONST_VALUE . "\n";
        echo self::$color . "\n";
    }
}

Apple::doubleColon();
?>

程序运行结果:

Fruit Color Red

Program List:调用parent方法

  
<?php
class Fruit
{
    protected function showColor() {
        echo "Fruit::showColor()\n";
    }
}

class Apple extends Fruit
{
    // Override parent's definition
    public function showColor()
    {
        // But still call the parent function
        parent::showColor();
        echo "Apple::showColor()\n";
    }
}

$apple = new Apple();
$apple->showColor();
?>

程序运行结果:

Fruit::showColor() 
Apple::showColor()

Program List:使用作用域限定符

  
<?php
    class Apple
    {
        public function showColor()
        {
            return $this->color;
        }
    }

    class Banana
    {
        public $color;

        public function __construct()
        {
            $this->color = "Banana is yellow";
        }

        public function GetColor()
        {
            return Apple::showColor();
        }
    }

    $banana = new Banana;
    echo $banana->GetColor();
?>

程序运行结果:

Banana is yellow

Program List:调用基类的方法

    
<?php

class Fruit
{
    static function color()
    {
        return "color";
    }

    static function showColor()
    {
        echo "show " . self::color();
    }
}

class Apple extends Fruit
{
    static function color()
    {
        return "red";
    }
}

Apple::showColor();
// output is "show color"!

?>

程序运行结果:

show color

来源:http://www.nowamagic.net/php/php_UsageOfDoubleColon.php

双冒号操作符即作用域限定操作符Scope Resolution Operator可以访问静态、const和类中重写的属性与方法。

在类定义外使用的话,使用类名调用。在PHP 5.3.0,可以使用变量代替类名。

Program List:用变量在类定义外部访问

    
<?php
class Fruit {
    const CONST_VALUE = 'Fruit Color';
}

$classname = 'Fruit';
echo $classname::CONST_VALUE; // As of PHP 5.3.0

echo Fruit::CONST_VALUE;
?>

Program List:在类定义外部使用::

  
<?php
class Fruit {
    const CONST_VALUE = 'Fruit Color';
}

class Apple extends Fruit
{
    public static $color = 'Red';

    public static function doubleColon() {
        echo parent::CONST_VALUE . "\n";
        echo self::$color . "\n";
    }
}

Apple::doubleColon();
?>

程序运行结果:

Fruit Color Red

Program List:调用parent方法

  
<?php
class Fruit
{
    protected function showColor() {
        echo "Fruit::showColor()\n";
    }
}

class Apple extends Fruit
{
    // Override parent's definition
    public function showColor()
    {
        // But still call the parent function
        parent::showColor();
        echo "Apple::showColor()\n";
    }
}

$apple = new Apple();
$apple->showColor();
?>

程序运行结果:

Fruit::showColor() 
Apple::showColor()

Program List:使用作用域限定符

  
<?php
    class Apple
    {
        public function showColor()
        {
            return $this->color;
        }
    }

    class Banana
    {
        public $color;

        public function __construct()
        {
            $this->color = "Banana is yellow";
        }

        public function GetColor()
        {
            return Apple::showColor();
        }
    }

    $banana = new Banana;
    echo $banana->GetColor();
?>

程序运行结果:

Banana is yellow

Program List:调用基类的方法

    
<?php

class Fruit
{
    static function color()
    {
        return "color";
    }

    static function showColor()
    {
        echo "show " . self::color();
    }
}

class Apple extends Fruit
{
    static function color()
    {
        return "red";
    }
}

Apple::showColor();
// output is "show color"!

?>

程序运行结果:

show color

升级后discuz X2勋章中心空白的解决方法

可能是升级上来的领取权限设置数据冲突造成。清空[pre]_forum_medal表的permission字段就可以正常显示了。不过估计勋章中心的领取权限要重新设置一遍。

受下面网页启发:http://x.discuz.net/thread-2231288-1-1.html

PHP多线程的实现

原文地址:http://hi.baidu.com/nbcc/blog/item/36a656a7deba579fd0435871.html

最近研究php多线程的问题,发现中文资源少的可怜,仅有的几篇文章被转了又转,但文中内容价值有限。搜索过程中发现国外很多网站引用的一篇文章写的不错,所以翻译过来。

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明
http://blog.iyi.cn/start/

问题:
有没有办法在php中实现多线程呢?

假设你正在写一个基于多台服务器的php应用,理想的情况时同时向多台服务器发送请求,而不是一台接一台。
可以实现吗?
回答:

当有人想要实现并发功能时,他们通常会想到用fork或者spawn threads,但是当他们发现php不支持多线程的时候,大概会转换思路去用一些不够好的语言,比如perl。

其实的是大多数情况下,你大可不必使用fork或者线程,并且你会得到比用fork或thread更好的性能。

假设你要建立一个服务来检查正在运行的n台服务器,以确定他们还在正常运转。你可能会写下面这样的代码:

<?php
$hosts = array("host1.sample.com", "host2.sample.com", "host3.sample.com");
$timeout = 15;
$status = array();
foreach ($hosts as $host) {
$errno = 0;
$errstr = "";
$s = fsockopen($host, 80, $errno, $errstr, $timeout);
if ($s) {
$status[$host] = "Connectedn";
fwrite($s, "HEAD / HTTP/1.0rnHost: $hostrnrn");
do {
$data = fread($s, 8192);
if (strlen($data) == 0) {
break;
}
$status[$host] .= $data;
} while (true);
fclose($s);
} else {
$status[$host] = "Connection failed: $errno $errstrn";
}
}
print_r($status);
?>

它运行的很好,但是在fsockopen()分析完hostname并且建立一个成功的连接(或者延时$timeout秒)之前,扩充这段代码来管理大量服务器将耗费很长时间。
因此我们必须放弃这段代码;我们可以建立异步连接-不需要等待fsockopen返回连接状态。PHP仍然需要解析hostname(所以直接使用ip更加明智),不过将在打开一个连接之后立刻返回,继而我们就可以连接下一台服务器。
有两种方法可以实现;PHP5中可以使用新增的stream_socket_client()函数直接替换掉fsocketopen()。PHP5之前的版本,你需要自己动手,用sockets扩展解决问题。

下面是PHP5中的解决方法:
<?php
$hosts = array("host1.sample.com", "host2.sample.com", "host3.sample.com");
$timeout = 15;
$status = array();
$sockets = array();
/* Initiate connections to all the hosts simultaneously */
foreach ($hosts as $id => $host) {
$s = stream_socket_client("$host:80", $errno, $errstr, $timeout,
STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT);
if ($s) {
$sockets[$id] = $s;
$status[$id] = "in progress";
} else {
$status[$id] = "failed, $errno $errstr";
}
}
/* Now, wait for the results to come back in */
while (count($sockets)) {
$read = $write = $sockets;
/* This is the magic function - explained below */
$n = stream_select($read, $write, $e = null, $timeout);
if ($n > 0) {
/* readable sockets either have data for us, or are failed
* connection attempts */
foreach ($read as $r) {
$id = array_search($r, $sockets);
$data = fread($r, 8192);
if (strlen($data) == 0) {
if ($status[$id] == "in progress") {
$status[$id] = "failed to connect";
}
fclose($r);
unset($sockets[$id]);
} else {
$status[$id] .= $data;
}
}
/* writeable sockets can accept an HTTP request */
foreach ($write as $w) {
$id = array_search($w, $sockets);
fwrite($w, "HEAD / HTTP/1.0rnHost: "
. $hosts[$id] . "rnrn");
$status[$id] = "waiting for response";
}
} else {
/* timed out waiting; assume that all hosts associated
* with $sockets are faulty */
foreach ($sockets as $id => $s) {
$status[$id] = "timed out " . $status[$id];
}
break;
}
}
foreach ($hosts as $id => $host) {
echo "Host: $hostn";
echo "Status: " . $status[$id] . "nn";
}

?>

我们用stream_select()等待sockets打开的连接事件。stream_select()调用系统的select(2)函数来工作:前面三个参数是你要使用的streams的数组;你可以对其读取,写入和获取异常(分别针对三个参数)。stream_select()可以通过设置$timeout(秒)参数来等待事件发生-事件发生时,相应的sockets数据将写入你传入的参数。

下面是PHP4.1.0之后版本的实现,如果你已经在编译PHP时包含了sockets(ext/sockets)支持,你可以使用根上面类似的代码,只是需要将上面的streams/filesystem函数的功能用ext/sockets函数实现。主要的不同在于我们用下面的函数代替stream_socket_client()来建立连接:
<?php
// This value is correct for Linux, other systems have other values
define('EINPROGRESS', 115);
function non_blocking_connect($host, $port, &$errno, &$errstr, $timeout) {
$ip = gethostbyname($host);
$s = socket_create(AF_INET, SOCK_STREAM, 0);
if (socket_set_nonblock($s)) {
$r = @socket_connect($s, $ip, $port);
if ($r || socket_last_error() == EINPROGRESS) {
$errno = EINPROGRESS;
return $s;
}
}
$errno = socket_last_error($s);
$errstr = socket_strerror($errno);
socket_close($s);
return false;
}
?>

现在用socket_select()替换掉stream_select(),用socket_read()替换掉fread(),用socket_write()替换掉fwrite(),用socket_close()替换掉fclose()就可以执行脚本了!
PHP5的先进之处在于,你可以用stream_select()处理几乎所有的stream-例如你可以通过include STDIN用它接收键盘输入并保存进数组,你还可以接收通过proc_open()打开的管道中的数据。
如果你想让PHP4.3.x自身拥有处理streams的功能,我已经为你准备了一个让fsockopen可以异步工作的patch。不赞成使用该补丁,该补丁不会出现在官方发布的PHP版本中,我在补丁中附带了stream_socket_client()函数的实现,通过它,你可以让你的脚本兼容PHP5。
附件:
documentation for stream_select()
documentation for socket_select()
patch for PHP 4.3.2 and script to emulate stream_socket_client(). (might work with later 4.3.x versions).

------------------------------------

经测试,确实为多线程,弄了整个下午,终于弄好了~~~


$request = array("http://10.1.30.218/test/server.php","http://10.1.30.28/server.php");

foreach($request as $r) {
$temp = parse_url($r);
$scheme[] = $temp['scheme'];
$hosts[] = $temp['host'];
$paths[] = isset($temp['path']) ? $temp['path'] : "" ;
}

//$hosts = array("www.bit.edu.cn");

$timeout = 5;
$status = array();
$sockets = array();
// Initiate connections to all the hosts simultaneously
foreach ($hosts as $id => $host) {
$s = stream_socket_client("$host:80", $errno, $errstr, $timeout, STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT);
if ($s) {
$sockets[$id] = $s;
$status[$id] = "in progress";
} else {
$status[$id] = "failed, $errno $errstr";
}
}
//print_r($sockets);print_r($status);
//*
// Now, wait for the results to come back in
while (count($sockets)) {
$read = $write = $sockets;
// This is the magic function - explained below
$ret = stream_select($read, $write, $e = null, $timeout);
if ($ret > 0) {
// readable sockets either have data for us, or are failed connection attempts
foreach ($read as $r) {
$id = array_search($r, $sockets);
$data = fread($r, 8192);
if (strlen($data) == 0) {
if ($status[$id] == "in progress") {
$status[$id] = "failed to connect";
}
fclose($r);
unset($sockets[$id]);
} else {
if ($status[$id] == "in progress") {
$status[$id] = $data;
} else {
$status[$id] .= $data;
}
}
}
// writeable sockets can accept an HTTP request
foreach ($write as $w) {
$id = array_search($w, $sockets);
//fwrite($w, "HEAD / HTTP/1.0\r\nHost: " . $hosts[$id] . "\r\n\r\n");
fwrite($w, "GET /".$paths[$id]." HTTP/1.0\r\nHost: " . $hosts[$id] . "\r\n\r\n");
//$status[$id] = "waiting for response";
}

} else {
// timed out waiting; assume that all hosts associated with $sockets are faulty
foreach ($sockets as $id => $s) {
$status[$id] = "timed out\r\n\r\n" . $status[$id];
}
break;
}
}
foreach ($hosts as $id => $host) {
echo "Host: $host\n";
echo '<pre>'.$status[$id].'</pre>';
/*
$pos = strpos($status[$id],"\r\n\r\n");
$content[$id] = substr($status[$id],$pos);
$status[$id] = substr($status[$id],0,$pos);
//echo "Status: " . $status[$id] . "\n\n";
echo $content[$id] . "\n\n" ;
*/
}

PHP异步调用、多线程、计划任务

PHP编程也能实现这些看起来很“高级”的编程任务。
异步调用一般用来执行耗时较长的操作,让程序在服务器后台执行,前台用户无需等待。参考这篇文章:PHP异步调用避免程序运行超时
案例:PHP语言
某SNS社区,在系统里,用户给自己的好友(好友数量上百)发送邮件,每封邮件内容不一,发送后提示发送完毕!
常用PHP写法
sendmail.php
<?php
$count=count($emailarr);//$emailarr数组为好友的邮件地址
for($i=0;$i<$count;$i++)
{
sendmail(.....);//发送邮件
}
echo ''发送完毕';
?>
假设该次发送100封邮件。本次操作会出现什么结果呢?

用户体验:用户等待->发送数十封邮件出去->系统超时返回错误信息

本次操作由于需要发送大量的邮件,导致php执行时间过长,用户烦躁的等待。当apache或者nginx等待超过允许执行时间,返回超时错误。这个时候用户不明确本次操作到底成功与否,到底发出了几封邮件。
我们可以看出该代码用户体验极差,并且不能够顺利完成任务。

那应该怎么操作呢?
这里提到一个概念,异步执行
用户体验:用户等待->发送完毕
朋友们就会问,怎么缺少发信环节?
OK,发信环节就在用户提交请求的时候,把发信任务转给了一个单独处理发信的php程序处理了,当用户看见“发送完毕”的时候其实信还没发送完,这个时候,发信程序正在后台努力的工作着,一封一封的向外发送

sendmail.php
<?php
$domain="www.***.com";
$url="/system_mail.php";
$par="email=".implode(',',$emailarr)."&........";
$header = "POST $url HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($par) . "\r\n\r\n";
$fp = @fsockopen ($domain, 80, $errno, $errstr, 30);
fputs ($fp, $header . $par);
fclose($fp);

echo ''发送完毕';
?>
system_mail.php
<?php
ini_set("ignore_user_abort",true);
ignore_user_abort(true);//此处的代码需要php.ini开启相关的选项,保证php执行不超时的,不明白,参考我的另一篇文章 “关闭浏览器后,php脚本会不会继续运行”
//获取email地址,发信,此处为发信代码
?>

好了,改成异步方式后,用户提交信息,可以立即得到结果“发送完毕”。信呢,会在后台一封一封的发送,直到发送完毕。

前几天用ASP.NET实现了计划任务功能,心里想,PHP或许也能实现,搜索了一下,确实也能实现。参考这篇文章:PHP计划任务的实现

php计划任务的实现 (zt)
文章分类:PHP编程
<?php
ignore_user_abort(); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
set_time_limit(0); // 执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去
$interval=60*5; // 每隔5分钟运行
do{
$fp = fopen('test.txt','a');
fwrite($fp,'test');
fclose($fp);
sleep($interval); // 等待5分钟
}while(true);
?>


php定时计划任务介绍2010-05-06 10:10以前对se特别感兴趣,但是自己又不会java,lucene等搜索引擎开发工具,于是不断挖掘php的功效。

最后发现php也可以做抓取,并且原理很易:直接获取页面源文件,然后通过正则或字符串的参照截取来获取需要的信息。但是性能上不能和搜索引擎的多线程抓取相比。

实现了上一步之后,又思考着,如果抓取可以自动定时获取,那么人工运行可执行页面也就省下来了。

后来也在一些php开源程序中了解到关于"计划任务"的效果:可以定时运行某程序,比如数据库备份,更新缓存,生成静态页面,生成网站地图等。

最近由于项目需要定时更新远程数据库到本地,网上搜了搜,还真找到了。

ignore_user_abort();函数搭配set_time_limit(0);和sleep($interval);即可实现以上自动更新。

先给出一个基本的范式,其中有个人的测试程序:

<?php
ignore_user_abort(); // run script in background
set_time_limit(0); // run script forever
$interval=30; // do every 15 minutes...
do{
$fp = fopen('text3.txt','a');
fwrite($fp,'test');
fclose($fp);
sleep($interval); // wait 15 minutes
}while(true);
?>

首先运行该程序,然后关闭该页面,程序仍然运行中,test会每隔30秒的填补到text3.txt文件。

实现效果如图:(略)

最后根据php手册简单介绍一些相关的知识:

1.连接处理:

在 PHP 内部,系统维护着连接状态,其状态有三种可能的情况:

0 - NORMAL(正常)
1 - ABORTED(异常退出)
2 - TIMEOUT(超时)

当 PHP 脚本正常地运行 NORMAL 状态时,连接为有效。当远程客户端中断连接时,ABORTED 状态的标记将会被打开。远程客户端连接的中断通常是由用户点击 STOP 按钮导致的。当连接时间超过 PHP 的时限时,TIMEOUT 状态的标记将被打开。

可以决定脚本是否需要在客户端中断连接时退出。有时候让脚本完整地运行会带来很多方便,即使没有远程浏览器接受脚本的输出。默认的情况是当远程客户端连接中断时脚本将会退出。该处理过程可由 php.ini 的 ignore_user_abort 或由 Apache .conf 设置中对应的"php_value ignore_user_abort"以及 ignore_user_abort() 函数来控制。如果没有告诉 PHP 忽略用户的中断,脚本将会被中断,除非通过 register_shutdown_function() 设置了关闭触发函数。通过该关闭触发函数,当远程用户点击 STOP 按钮后,脚本再次尝试输出数据时,PHP 将会检测到连接已被中断,并调用关闭触发函数。

脚本也有可能被内置的脚本计时器中断。默认的超时限制为 30 秒。这个值可以通过设置 php.ini 的 max_execution_time 或 Apache .conf 设置中对应的"php_value max_execution_time"参数或者 set_time_limit() 函数来更改。当计数器超时的时候,脚本将会类似于以上连接中断的情况退出,先前被注册过的关闭触发函数也将在这时被执行。在该关闭触发函数中,可以通过调用 connection_status() 函数来检查超时是否导致关闭触发函数被调用。如果超时导致了关闭触发函数的调用,该函数将返回 2。

需要注意的一点是 ABORTED 和 TIMEOUT 状态可以同时有效。这在告诉 PHP 忽略用户的退出操作时是可能的。PHP 将仍然注意用户已经中断了连接但脚本仍然在运行的情况。如果到了运行的时间限制,脚本将被退出,设置过的关闭触发函数也将被执行。在这时会发现函数 connection_status() 返回 3。

2.相关函数:

int ignore_user_abort ( [bool setting] )
This function sets whether a client disconnect should cause a script to be aborted. It will return the previous setting and can be called without an argument to not change the current setting and only return the current setting.

int connection_aborted ( void )
Returns TRUE if client disconnected.

int connection_status ( void )
Returns the connection status bitfield.

至于多线程这个课题,参考一下这篇文章:PHP多线程

iis7 下配置PHP支持:适合win7和server 2008

首先,你必须安装IIS。这个就不多说了。

其次,安装一个叫PHP Manager的IIS插件。来这里下载:http://phpmanager.codeplex.com/

安装后,在IIS面板中,会出现PHP Manager管理图标。注意,建议在IIS根节点进行PHP Manager配置,这样配置完之后所有的网站就都支持了。

IIS-PHP1.jpgIIS-PHP2.jpg

使用PHP Manager可以让你方便的切换PHP版本——甚至不同的站点,可以使用不同的PHP版本。

注意,如果配置后无法打开默认文档配置,请到站点根目录下面的web.config文件中,删除<files>节点下的所有add配置。这样站点将集成IIS的默认配置。

IIS-PHP3.jpg

PHP各版本下载:http://windows.php.net/downloads/releases/

顺便说一下,这种方式是以 FastCGI模式运行的。比配置ISAPI方式运行及灵活又高效。真是PHP开发者的福音!

您还可以安装 

Windows Cache Extension for PHP

来为PHP提速。

参考链接:http://hi.baidu.com/tjcm/blog/item/399859dac83397c9b7fd4803.html

关于解决"cannot modify header information - headers already sent by"的错误

 

一个上传文件的功能,上传成功 返回信息的时候经常提示:cannot modify header information - headers already sent by (......)。其实已经实现需要的效果了,就是这个错误信息看着不爽,网上找了很多办法,综合使用得到的解决方法是

1在页面顶部的php标签中加入ob_start();

2在返回的信息下面加入ob_end_flush();

这样就可以屏蔽错误信息的现实了

另外转一下其他人的方法,也许在其他情况下也会有效

If you got this message: "Warning: Cannot modify header information - headers already sent by ...."
如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ...."

Few notes based on the following user posts:
有以下几种解决方法:

1. Blank lines (空白行):
Make sure no blank line after <?php ... ?> of the calling php script.
检查有<?php ... ?> 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。

 

 

2. Use exit statement (用exit来解决):
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit();

 

3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it'll said "Warning: Cannot modify header information - headers already sent by ...." Basically anytime you output to browser, the header is set and cannot be modified.   So two ways to get around the problem:

3a. Use Javascript (用Javascript来解决):
<? echo "<script> self.location(\"file.php\");</script>"; ?>
Since it's a script, it won't modify the header until execution of Javascript.
可以用Javascript来代替header。但是上面的这段代码我没有执行成功... 另外需要注意,采用这种方法需要浏览器支持Javascript.

3b. Use output buffering (用输出缓存来解决):
<?php ob_start(); ?>
... HTML codes ...
<?php
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>
This will save the output buffer on server and not output to browser yet, which means you can modify the header all you want until the ob_end_flush() statement.   This method is cleaner than the Javascript since Javascript method assumes the browser has Javascript turn on.   However, there are overhead to store output buffer on server before output, but with modern hardware I would imagine it won't be that big of deal.   Javascript solution would be better if you know for sure your user has Javascript turn on on their browser.

就像上面的代码那样,这种方法在生成页面的时候缓存,这样就允许在输出head之后再输出header了。本站的许愿板就是采用这种方法解决的header问题。

后台管理或者有时候在论坛,点击一个页面,页顶会出现
Warning: Cannot modify header information - headers already sent by....
这类语句,造成这个原因是因为setcookie语句的问题。

cookie本身在使用上有一些限制,例如:
1.呼叫setcookie的敘述必須放在<html>標籤之前
2.呼叫setcookie之前,不可使用echo
3.直到網頁被重新載入後,cookie才會在程式中出現
4.setcookie函數必須在任何資料輸出至瀏覽器前,就先送出
5.……
基於上面這些限制,所以執行setcookie()函數時,常會碰到"Undefined index"、"Cannot modify header information - headers already sent by"…等問題,解決"Cannot modify header information - headers already sent by"這個錯誤的方法是在產生cookie前,先延緩資料輸出至瀏覽器,因此,您可以在程式的最前方加上ob_start();這個函數。这样就可以解决了。

 

4.set output_buffering = On in php.ini (开启php.ini中的output_buffering )
set output_buffering = On will enable output buffering for all files. But this method may slow down your php output. The performance of this method depends on which Web server you're working with, and what kind of scripts you're using.
这种方法和3b的方法理论上是一样的。但是这种方法开启了所有php程序的输出缓存,这样做可能影响php执行效率,这取决于服务器的性能和代码的复杂度。

来源:http://hi.baidu.com/xiaefun/blog/item/87fd5f82e96a3eaa0df4d2cb.html

eclipse改变charset

eclipse有时候默认的编码不正确,这是需要我们手工改变编码集。

1、改变整个工作区的编码集:

通过 window - preferences - workspace 中的选项设置。

eclipse-charset1.jpg

2、改变项目或文件的编码集:

在eclipse的资源管理器中右击项目或文件,选择属性,其中的resouce选项卡进行设置。

eclipse-charset2.jpg

参考链接:http://wiki.objectstyle.org/confluence/display/WOL/Setting+the+default+text+encoding+for+Eclipse

公告栏

  • 姓名:林剑锋(不见不散)
  • 来自:中国-广州
  • 简介:技术的信徒。
  • Email/QQ:admin@ljf.cn
  • 点击这里给我发消息

QQ群:设计学院 68075618,网站设计师 9908776

统计

文章:337篇
评论:173条 (2条Spam)
相册:1个 (121张图片)
主题:Nagrand新主题

www.ljf.cn网站PR查询