+ 7

Why we always set session_start() at the top of php pages

15th May 2017, 11:53 AM
Said BAHAOUARY
Said BAHAOUARY - avatar
4 odpowiedzi
+ 21
Some functions like this and setcookie() must come before html in latest versions of php thus it is usually located on top (you can put it after html if you put ob_start() at the begining instead.....)
15th May 2017, 11:57 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 9
thanks @ValentineHacker but I m just looking for if there is a reason why?
15th May 2017, 12:18 PM
Said BAHAOUARY
Said BAHAOUARY - avatar
+ 3
You cannot have any type of output to the browser before starting a session.
24th May 2017, 7:09 AM
Sello Selby Bopape
Sello Selby Bopape - avatar
+ 3
you don't want to load your headers before session start
24th May 2017, 7:10 AM
Sello Selby Bopape
Sello Selby Bopape - avatar