jorel jorel - 1 year ago 71
PHP Question

PHP seems to execute script twice

My web server is acting wierd. It seems like it executes scripts (PHP) twice before sending then to apache.

I've run this file:

echo '<pre>';
echo '<br>';

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.

The webserver is apache2, php5 installed on a debian unit.

Anyone has any ideas?

Answer Source
echo '<pre>'; //Headers and cookies already sent.
session_start(); //Cannot set cookie anymore, system tries again, I guess

Start session first, then output anything. Try placing session_start(); on top

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download