So i am trying to make a Register/Login system on my site. Note that i didn't write the scripts. The Registration works fine and the user info are stored in the database. But when i go to the login page i get these errors:
My original script for login.php was:PHP Code:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/kg/public_html/login.php:1) in /home/kg/public_html/login.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/kg/public_html/login.php:1) in /home/kg/public_html/login.php on line 2
After some search i was told to add ob_start(); after session_start(); and ob_end_flush(); just before the ?> tag. But that didnt work :/PHP Code:<?php
session_start();
$conn = mysql_connect('localhost', '******, '*****') or die(mysql_error());
mysql_select_db('*****', $conn);
if(isset($_GET['try'])) {
If(empty($_POST['username']) OR empty($_POST['password'])) {
echo 'Please fill in all the required fields!';
} else {
$username = mysql_real_escape_string($_POST['username']);
$password = md5($_POST['password']);
$query = mysql_query("SELECT id FROM login
WHERE username = '" . $username . "'
AND password = '" . $password . "'
") or die(mysql_error());
list($user_id) = mysql_fetch_row($query);
if(empty($user_id)) {
echo 'No combination of username and password found.';
} else {
$_SESSION['user_id'] = $user_id;
header('location: index.html');
}
}
}
?>
Since i am not that fond of php and my experience with it is very limited i couldnt get past this problem, although i noticed that the script isnt checking if the user is already logged in. So i tried to alter the script with the hope that if it somehow checked if the user is logged in this problem would be fixed.
The result was that:
But it still isnt working. However it is printing the "You are already logged in" message under the errors.PHP Code:<?php
session_start();
ob_start();
$conn = mysql_connect('localhost', '******', '******') or die(mysql_error());
mysql_select_db('*****', $conn);
if(!(isset($_SESSION['user_id']))) {
if(isset($_GET['try'])) {
If(empty($_POST['username']) OR empty($_POST['password'])) {
echo 'Please fill in all the required fields!';
} else {
$username = mysql_real_escape_string($_POST['username']);
$password = md5($_POST['password']);
$query = mysql_query("SELECT id FROM login
WHERE username = '" . $username . "'
AND password = '" . $password . "'
") or die(mysql_error());
list($user_id) = mysql_fetch_row($query);
if(empty($user_id)) {
echo 'No combination of username and password found.';
} else {
$_SESSION['user_id'] = $user_id;
header('location: index.html');
}
}
}else{
echo 'You are already logged in.';
}
}
ob_end_flush();
?>
If someone doesnt mind looking into it i would appreciate it. And dont worry i will understand whatever u tell me, i have some experience with programming just not that much with php yet.
My site is aniwalls.exofire.net. Under Constuction ofc.


LinkBack URL
About LinkBacks
Reply With Quote


icon below! (this is even better than "liking" a post)

