17 Replies
When this isn't returns any error in the php:
there is no PHP code here
I'll provide more info in a sec
headers already sent is usually the case if you try to use the
header
function after you've already sent text to the browser, either outside of <?php ?>
or using echo
/print
it throws the errors at this place: html
<b>Warning</b>: ini_set(): Session ini settings cannot be changed after headers have already been sent on line <b>131</b><br />
<br />
<b>Warning</b>: session_start(): Session cannot be started after headers have already been sent on line <b>132</b><br />
<br />
<b>Warning</b>: Undefined global variable $_SESSION on line <b>134</b><br />
<br />
<b>Warning</b>: Trying to access array offset on value of type null on line <b>134</b><br />
There is a JS code what checks if the user is logged or not, and it is getting a response from another php about the user status. That contains an echo, but with the first html form is working
where is line 131? is that the ini_set line?
yes
also, why on earth are you using ini_set? Just change php.ini
but thats should not be the problem
It is part of it though
ini_set(): Session ini settings cannot be changed after headers have already been sentcan you share the rest of the file?
sure
PHP can send headers along with the response Apache or nginx sends to the user, but it can only do that before there is any other output. Once there's other output sent, the server will have to end the part of the response where the headers live, and start the part of the response where the body (output of your PHP file) lives.
Some things have to be done before the headers are sent, stuff like starting a session or setting an ini directive
The file you shared has a ton of HTML and JS before your
<?php
opening tag. That means that PHP will read all that, and send it to the server as output, which will then by necessity close the phase of the response where it can send headers, and start sending the body
basically, if you want to start a session and change ini settings, your file has to start with a php block (<?php
through ?>
), and those function calls have to be before any echos, prints, or other things that send output to the browserthen should I remove the php from the body and put it to the begining of the file outside the html tag?
that would probably work yeah
alright
and its working
what an amateur problem
thank you for your help
I really appreciate it
no worries