首页 > 编程技术 > php

关于使用 session_start 出现的 headers 

发布时间:2016-11-25 17:41

请看详细的错误程序和输出结果
<html>
<?
echo "testing ... ";
session_start();
?>
</html>
输出为
testing ...
Warning: Cannot send session cookie - headers already sent by (output started at F:php2000test.php:2) in F:php2000test.php on line 4
Warning: Cannot send session cache limiter - headers already sent (output started at F:php2000test.php:2) in F:php2000test.php on line 4
分析:
主要原因,php.ini里有关于session 的定义,默认是使用 cookie
[session]
session.use_cookies = 1 ; whether to use cookies
这句表明使用 cookies 存储session 而 cookies的设置必须在正式 htm 之前,也就是只能在 header 里面才行,所以造成这个错误的发生
我们修改程序为
<?
echo "testing ... ";
session_start();
?>
同样错误,因为 echo 已经输出了
我们修改程序为
<?
$i=1;
session_start();
?>
运行正确表明在session_start的前面可以有计算语句,但是不能有输出语句
我尝试过修改
session.use_cookies = 0 ; whether to use cookies
但是没有成功,希望知道答案的朋友通知我,如何去掉cookie方式的 session

MySQL是可以远程调用的,但用户要有远程调用的权限。
在增加用户的时候有一个host 选项,是任何主机 或 locahost,你选用 any host,这样,你就可以远程调用了。
mysql_pconnect("192.168.0.2:3306","root","password");
这是因为PHP。INI中有一些设置不对,最有可能是就是有无效的DLL文件在内。但为什么会出现这些呢?
我在WIN32下,建了一个空的test.php文件。
然后执行c:php4php.exe test.php,此时我的php.ini的配置是正确的。屏幕输出为:
X-Powered-By: PHP/4.0.0
Content-type: text/html
咦,这不是显示在屏幕上的东西吗?是的。但这时这两行是作HTTP信息头的。是不会显示在浏览器中的。
现在我在php.ini中加载了php_mysql.dll。而这个文件是不存在的。
再次执行c:php4php.exe test.php,屏幕输出为:
Content-type: text/html
PHP Fatal error: Unable to load dynamic library 'php_mysql.dll'
此处还有些乱字符
X-Powered-By: PHP/4.0.0
Content-type: text/html
就是在Content-type: text/html之后,又出现了一些错误信息,所以才导致X-Powered-By: PHP/4.0.0 Content-type: text/html出现在屏幕上。而这其实本来是HTTP的信息头的。
那么我想在出这些错时,如果output_buffering=off的话,那么setcookie()是没办法使用的。
明白了吗?
当然可以,PHP中有个函数number_format,函数原型:
        string number_format
        (
           float number,
           int decimals,
           string dec_point,
           string thousands_sep
        )
    举个例子:
        <?
        $num = 12345678.9;
        echo number_format($num).'<br>'; //会4舍5入
        echo number_format($num,2).'<br>';
        echo number_format($num,2,':').'<br>'; //这种写法是错误的
        echo number_format($num,2,':','-').'<br>';
        ?>
    输出结果为:
        12,345,679
        12,345,678,90
        Warning: Wrong parameter count for number_format() in /data/homepage/test/number_format.php on line 5
        12-345-678:90

这是IIS的安全模式有问题。这是所有CGI脚本在IIS下面运行都会遇到的问题。它先建立完全的HTML文件(不通过PHP解析)后通过使用者认证路径进入该页。当使用META标记重新导向PHP页面,或者连接到PHP页面时,PHP将确认正确的认证。当ISAPI模块可用时,这就不在是问题。这个问题不会影响到其它的NT WEB服务器。更多的信息请参考:
http://support.microsoft.com/support/kb/articles/q160/4/22.asp。
标签:[!--infotagslink--]

您可能感兴趣的文章: