Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\header.php:7) in D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\index.php on line 52
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\header.php:7) in D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\index.php on line 52
Warning: Cannot modify header information - headers already sent by (output started at D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\header.php:7) in D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\index.php on line 54
- 5,396
- 14
- 39
- 46
- 3
- 5
-
1Possible duplicate of [How to fix "Headers already sent" error in PHP](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Kirk Beard Apr 01 '18 at 07:07
-
Please, format your question properly with code blocks so it would be easier to read. See https://stackoverflow.com/help/how-to-ask for more instructions – Sergey Mell Apr 01 '18 at 07:23
1 Answers
Your are just posting error without posting your code. How do you expect to get the correct response from stackoverflow. Do you think Stackoverflow are Spirit who can interpret what is in the peoples mind.
The possible issue with the error you sent is that may be you initialize php session numerous places.
1.) Check to ensure that you did not initialized session(session_start();) in more than one place on that page.
2.) You are recieving error packet already sent because you are trying to send html in php pages. This error can remove by setting ob_start() at the begining of your page and ob_flush_end() at the very bottom of the page.
Of course you can also disable error notice with error_reporting(0) functions
so you code might look like
<?php
error_reporting(0);
ob_start();
/* You can initialized here and ensure you did not set it any other place on the same pge"/
session_start();
// your page content here
//at the bottom of page
ob_flush_end();
?>
The error will be gone
An updated Answer based on your post is here and it works.
<html>
<head><body>
<form action="log.php" method="post">
name: <input type="" name="username"><br>
password: <input type="" name="password"><br>
<input type="submit" name="login" value="login"><br>
</form>
</body>
</html>
<?php
error_reporting(0);
ob_start();
if (isset($_POST['login'])) {
session_start();
$con = mysqli_connect("localhost","root","","myfriend_db");
$username=$_POST['username'];
$password=$_POST['password'];
$result=mysqli_query($con,"select * from users where username='$username' and password='$password'")or die (mysqli_error());
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
if ($count > 0) {
$_SESSION['id']=$row['id'];
header('location:admin.php');
}else{
echo "error: username and password not found";
echo "<br> <div class='alert alert-error'> <button type='button' class='close' data-dismiss='alert'>×</button>";
}
}else{
echo "login value not set in the form";
}
ob_flush_end();
?>
Bear in mind that your code is vulnerable to various kind of attack Sql Injection, html injection, xss attack, session fixation and hijacking, buffer overflow, input attack and many more.... try to implement all this security before deploying in production.
- 517
- 6
- 19
-
0) { session_start(); $_SESSION['id']=$row['id']; header('location:admin.php'); }else{ ?>
– Ricky Apr 01 '18 at 11:36 -
i have updated your code in the answer above. don't use uppercase when initializing a variable. I see u setting username to $Username. you will get confuse. Run the code above i updated and you will be fine. – chinazaike Apr 01 '18 at 12:13
-
-
See, I have tried my best for you. You sent a code I have updated it and it runs very perfect. See my answer to get my updated part of the code that runs perfectly. I do not know which code that you are referencing again that is not working. I do not give you only a guidance I also updated your code to work very well. see my answer – chinazaike Apr 03 '18 at 20:24
-
Just a tip. In the else condition. you just say
. why are not printing it with echo(). you also need to know how you work with both single and double quote. see my updated part of the answer that I posted. it works for you– chinazaike Apr 03 '18 at 20:28 -
If you need project done for you, you can contact Stackoverflow.com Senior Engineers, they will be able to do it for you. stay tuned..... – chinazaike Apr 03 '18 at 20:37