Possible Issues When Working with Sessions in PHP
The main issue when working with sessions is the following: no output can be sent to the browser before finishing work with sessions, otherwise you will see the following error: Warning: Cannot send session cookie - headers already sent.
What is output to the browser? It is any character
before <?php, for example, text or a tag,
even a space, as well as an error message
from PHP. Furthermore, you cannot make
output via echo, var_dump
and print_r.
Your document's encoding must necessarily
be utf-8 without BOM. If it is
just utf-8, then a special character specific
to this encoding will be inserted before <?php
and the sessions will not work.
Fix the errors in the following code:
text
<?php
session_start();
?>
Fix the errors in the following code:
<p>
<?php
session_start();
?>
</p>
Fix the errors in the following code:
<?php
echo 'text';
session_start();
?>