Nefferson Posted July 25, 2016 Share Posted July 25, 2016 hello there! i am new to php ! i was trying to create a login form. in line 202 <form class="login-form" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> so i can make the verification process on the same page and send the errors to the users when there are some . if there is no error (i.e all data correct) process data and make connection to database(mysql), put the data(username, password, email) in table, then at least redirect user to the home page with (header('Location: homepage.php'). but i got an error while loading page. I know why the problem. I just want someone to give me an advice on how to solve it. please help me !!!! Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/ Share on other sites More sharing options...
benanamen Posted July 25, 2016 Share Posted July 25, 2016 Try posting your code. Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534966 Share on other sites More sharing options...
mac_gyver Posted July 25, 2016 Share Posted July 25, 2016 if you read the error message, it tells you where the OUTPUT is occurring at, that is preventing the header() statement from working. the way to fix this is to find and prevent the output from occurring before the header() statement. this may involve rearranging your code so that the logic containing the header() statement comes near the top of your code, before you produce and output any html. Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534967 Share on other sites More sharing options...
Nefferson Posted July 25, 2016 Author Share Posted July 25, 2016 i found another solution. what i wanted to do is to redirect automaticly my user to the homepage after registering his data input in the data base after registering on my webpage. so i created a variable $redirect = ''thanks for registering, please click here to get access to all our services" and then i put a link <a href="homapage.php">Homepage</a>. thus he can keep going by himself on the next pages. Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534970 Share on other sites More sharing options...
Jacques1 Posted July 25, 2016 Share Posted July 25, 2016 That's silly. When your code doesn't do what it should, the solution is to fix it, not make your users click on links. You'll probably encounter the same problem many more times, so why don't you take the chance to understand it and avoid it in the future? Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534971 Share on other sites More sharing options...
Nefferson Posted July 25, 2016 Author Share Posted July 25, 2016 That's silly. When your code doesn't do what it should, the solution is to fix it, not make your users click on links. You'll probably encounter the same problem many more times, so why don't you take the chance to understand it and avoid it in the future? if you can give me any idea, i would be really grateful. the fact is that i made somee researches, and based on waht i found, it was like there nothing i could do to fix it. the only other solution i saw, was to send all the data to another page <action="verify.php"> and then retrieve the data with $_POST[] and make the connection to the database, after storing the data in tables, redirect user to homage with (header) but my problem was, what if the user didnt enter all the data from the form. i would like to send an error message to notify him there is a data missing but i am not good enough to do this, so i had to find a solution. but if you have any idea, please tell me. Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534975 Share on other sites More sharing options...
Jacques1 Posted July 25, 2016 Share Posted July 25, 2016 Post your code. The solution is to first do all PHP processing, and then generate the HTML markup: <?php // PHP code goes here ?> <!DOCTYPE HTML> <!-- HTML markup goes here --> This way there will never be any output before a header() call. It also leads to much cleaner and more maintainable code, because the business logic (PHP) is cleanly separated from the representational part (HTML). Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534977 Share on other sites More sharing options...
Nefferson Posted July 25, 2016 Author Share Posted July 25, 2016 Post your code. The solution is to first do all PHP processing, and then generate the HTML markup: <?php // PHP code goes here ?> <!DOCTYPE HTML> <!-- HTML markup goes here --> This way there will never be any output before a header() call. It also leads to much cleaner and more maintainable code, because the business logic (PHP) is cleanly separated from the representational part (HTML). I tried it and it worked !!! thank you so much !!! Quote Link to comment https://forums.phpfreaks.com/topic/301578-cannot-modify-header-information-headers-already-sent-by/#findComment-1534978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.