Titan85
01-11-2007, 08:37 PM
I have been working on a login script for a while now and finally got it to work, but it seems that even though the login is a success, the session is not set. Here is my code for setting the session:
if($pass = $q['password']) {
echo 'You are now logged in! <br />
<a href="admin/">Control Panel</a>';
session_start();
$_SESSION['user'] = $username; // Set username session
$_SESSION['pass'] = $pass; // Set password session
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; // Set ip session
}
else {
echo'Login attempt failed. <br />
<a href="login.php">Retry</a>';
}When I login, it gives the success message, but an error as well. Here is the error: "Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/bntqann/public_html/testing/login/login.php:22) in /home/bntqann/public_html/testing/login/login.php on line 24". I don't get why it is saying that since the session_start() that it says is failing is the one it is saying is already set.
If it is set, then there must be something wrong with how I am checking for it, here is what I have:
<?php
if(empty($_SESSION['user']) && empty($_SESSION['pass']) && $_SESSION['ip'] != $_SERVER['REMOTE_ADDR']) {
header('Location: register.php');
}
else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Test</title>
</head>
<body>
If you can see this, you are logged in!
</body>
</html>
<?
}
?>Thanks for any help :)
if($pass = $q['password']) {
echo 'You are now logged in! <br />
<a href="admin/">Control Panel</a>';
session_start();
$_SESSION['user'] = $username; // Set username session
$_SESSION['pass'] = $pass; // Set password session
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; // Set ip session
}
else {
echo'Login attempt failed. <br />
<a href="login.php">Retry</a>';
}When I login, it gives the success message, but an error as well. Here is the error: "Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/bntqann/public_html/testing/login/login.php:22) in /home/bntqann/public_html/testing/login/login.php on line 24". I don't get why it is saying that since the session_start() that it says is failing is the one it is saying is already set.
If it is set, then there must be something wrong with how I am checking for it, here is what I have:
<?php
if(empty($_SESSION['user']) && empty($_SESSION['pass']) && $_SESSION['ip'] != $_SERVER['REMOTE_ADDR']) {
header('Location: register.php');
}
else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Test</title>
</head>
<body>
If you can see this, you are logged in!
</body>
</html>
<?
}
?>Thanks for any help :)