Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\xampp\htdocs\games\space\game.php:4) in C:\xampp\xampp\htdocs\games\space\game.php on line 7
The real error is this: you already sent headers. That means your server decided to flush the page before YOU as a programmer want it to do that.
Below session_start(); type this: ob_start();
and, on the end of the script type this: ob_flush(); this should flush the page only after that command, all code in between ob_start en ob_flush will now be executed before anything else.
There`s a difference in PHP`s $_SESSION and $_COOKIE. Even though both are kinda like the same, the $_SESSION is a cookie that only runs in the running cache of the browser. That means, a session only lives for as long as that page/site is open and the browser is open. Once the browser is closed, so long is your session ( which is a good thing, really.. ) Anyway, I work with sessions too, cookies are privacy crackers hihihaha.
<?php
include 'connect.php';
session_start();
if (isset($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);
$query = "select name,password from players where name='$player' and '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$name = $playerinfo3['name'];
echo "<h1>Welcome " . $name . "<br>";
echo '<meta http-equiv="refresh" content="0; URL=game.php">';
}
else
{
echo "Wrong username or password.<A href='login.php'>Try Again</a>";
}
}
?>
It keeps sending me to wrong username, event if the username is right.. i never got this error with this code because its old! i think the right thing to say now is: WTF IS GOING ON WITH THIS? xD
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\xampp\htdocs\browser\enter.php:2) in C:\xampp\xampp\htdocs\browser\enter.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\xampp\htdocs\browser\enter.php:2) in C:\xampp\xampp\htdocs\browser\enter.php on line 4
Wrong username or password.Try Again
The page should always start with <?php so you don`t confuse the interpreter. But regardless, the ob_start(); method is only a means to an end. It works, that`s not the problem, however you shouldn`t have to use it.