PHP似乎执行了两次脚本 [英] PHP seems to execute script twice
本文介绍了PHP似乎执行了两次脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Web服务器运行异常.似乎它先执行两次脚本(PHP),然后再发送给Apache.
My web server is acting wierd. It seems like it executes scripts (PHP) twice before sending then to apache.
我已经运行了该文件:
<?php
echo '<pre>';
session_start();
$_SESSION['index']++;
echo '<br>';
print_r($_SESSION);
?>
我知道++首先会发出通知,但这只是为了研究它是否运行两次.无论如何,打印的会话显示每次加载页面时index-index都会增加2.
And I know that ++ will give a notice at first, but it's just to investigate if it runs twice. Anyway, the printed session shows that the index-index increases by two each time you load the page.
该网络服务器是apache2,安装在debian单元上的php5.
The webserver is apache2, php5 installed on a debian unit.
有人有什么想法吗?
推荐答案
echo '<pre>'; //Headers and cookies already sent.
session_start(); //Cannot set cookie anymore, system tries again, I guess
首先启动会话,然后输出任何内容.尝试将 session_start();
放在顶部
Start session first, then output anything.
Try placing session_start();
on top
这篇关于PHP似乎执行了两次脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文