DiveInto
DiveInto

Reputation: 2266

why can't outputing anything before Session_Start()?

I can't figure out why ,anyone any help?

Upvotes: 2

Views: 152

Answers (1)

roman
roman

Reputation: 11278

simple: session_start sets your php session cookie, and cookies can only be set in the http header. php must send the header before it can start sending content. so as soon as you start to output content, php implicitly sends the http header and thus disables changing header values.

a common way to prevent this is to use output buffering - see http://php.net/manual/de/ref.outcontrol.php

Upvotes: 6

Related Questions