0

I've got this error
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/siambidd/domains/siambidding.com/public_html/session.php:3) in /home/siambidd/domains/siambidding.com/public_html/session.php on line 4

I've checked my code, there is no any spaces,
and I'm not using BOM as well, but still got this error.
please help me
here is my code

<html>
<head>
<?php
session_start();
ob_start();
include('connection.php');
$username = $_POST['username'];
$password = $_POST['password'];
$remember = $_POST['remember'];
$sql = ("SELECT * FROM users WHERE username='$username'");
$result = mysql_query($sql);
if ($result)
{
    $rows = mysql_fetch_array($result);
    $passwordx = $rows['password'];
    if ($password == $passwordx)
    {
        $_SESSION[ses_id] = session_id();
        $_SESSION[ses_username] = $username;

        echo "<meta http-equiv='refresh' content='0;url=session.php'>";
    }
    else
    {    
        echo "รหัสผ่านไม่ถูกต้อง";
    }
}
else
{
    echo "ไม่พบ username นี้ใระบบ";
}
?>
</head>
<body>
</body>
</html>

Edited by Nick Evan: Fixed formatting

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by aidant
0

session_start() must be the first statement....
So just remove it and place it at top...

<?php
session_start();
?>
<html>
<head>
<?php

ob_start();
include('connection.php');
$username = $_POST['username'];
$password = $_POST['password'];
$remember = $_POST['remember'];
$sql = ("SELECT * FROM users WHERE username='$username'");
$result = mysql_query($sql);
if ($result)
{
$rows = mysql_fetch_array($result);
$passwordx = $rows['password'];
if ($password == $passwordx)
{
$_SESSION[ses_id] = session_id();
$_SESSION[ses_username] = $username;

echo "<meta http-equiv='refresh' content='0;url=session.php'>";
}
else
{ 
echo "รหัสผ่านไม่ถูกต้อง";
}
}
else
{
echo "ไม่พบ username นี้ใระบบ";
}
?>
</head>
<body>
</body>
</html>

PS-If your problem is solved mark the thread as solved

Edited by tomato.pgn: n/a

0

I've tried it, and it didn't work.
I've tried ob_start() as well, it just got the same error.

0

<?php
session_start();
include('connection.php');
$username = $_POST;
$password = $_POST;
$remember = $_POST;
$sql = ("SELECT * FROM users WHERE username='$username'");
$result = mysql_query($sql);
if ($result){
$rows = mysql_fetch_array($result);
$passwordx = $rows;
if ($password == $passwordx){
$_SESSION[ses_id] = session_id();
$_SESSION[ses_username] = $username;

echo "<meta http-equiv='refresh' content='0;url=session.php'>";
} else {
echo "รหัสผ่านไม่ถูกต้อง";
}
} else {
echo "ไม่พบ username นี้ใระบบ";
}
?>
<html>
<head>
</head>
<body>
</body>
</html>

Edited by aidant: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.