You are here: Session warning « PHP « IT news, forums, messages
Session warning

Posted by Thomas Bonham on 10/21/19 11:21

Hello All,
I'm working on session and I'm getting this warning. Maybe someone can
help fixing this problem. Below is the following code.

Warning:
Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
/var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
3

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/var/www/html/bonham/cornerstone-data/property/adminlogin.php:2) in
/var/www/html/bonham/cornerstone-data/property/adminlogin.php on line
3


Then I get my login fields.

Code:
<?php
session_start();
require("functlib.php");
?>
<html>
<head>
<title>CIS166AE - Admin Login</title>
<link rel="stylesheet" type="text/css" href="/../../css/table.css">
</head>
<body>


<?php
if(isset($_POST['txtUser']) && isset($_POST['txtPass']))
{
if(CheckUser($_POST['txtUser'],$_POST['txtPass']))
$_SESSION['valid_user']=$_POST['txtUser'];
}

if(CheckAuth()==false)
{
//Code to make authentication
?>
<form method="post" action="adminlogin.php" name="login">
Please Login
Username:
<input name="txtUser" type="text">
Password:
<input name="txtPass" type="password">
<input type="submit" value="Login">
<input type="reset" value="Clear">"
</form>
<?php
}
else
{
//Code if authenticated
echo "Thank you, you have been authenticated as
<b>".$_SESSION['valid_user']."</b><br>";

}
?>

<?php if(isset($_SESSION['valid_user'])){echo "<a
href=\"adminlogout.php\">Logout</a>";}?>

</body>
</html>

Function FIle:
<?php
//PHP Functions that can be included in pages

function CheckAuth()
{
if(isset($_SESSION['valid_user']))
return true;
else
return false;
}

function CheckUser($username, $password)
{
$db = new mysqli('localhost','bonham','password_goes here','bonham');

$sql="Select * from auth where username = '".$username."' and
password = '".$password."'";
$result=$db->query($sql);
$db->close();
if($result->num_rows>0)
return true;
else
return false;
}

?>

Thank for the help.
Thomas
--
------------------------------------------------------------------
Thomas Bonham
thomasbbonham@gmail.com
bonhamlinux.org
Cell 602-402-9786

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация