<?
session_start();
function fncAuthentication() {
header('WWW-Authenticate: Basic realm="localhost"');
header("HTTP/1.0 401 Unauthorized");
exit;
}
//*** Check user ***//
if (trim($_SERVER['PHP_AUTH_USER'])!= "" and trim($_SERVER['PHP_AUTH_PW']) != "")
{
mysql_connect("localhost","root","root");
mysql_select_db("pj");
$strSQL = "SELECT * FROM user WHERE User = '".trim($_SERVER['PHP_AUTH_USER'])."'
and Password = '".trim($_SERVER['PHP_AUTH_PW'])."'";
$objQuery = mysql_query($strSQL);
if(mysql_fetch_array($objQuery))
{
$_SESSION["strUser"] = $_SERVER['PHP_AUTH_USER'];
$_SESSION["strPass"] = $_SERVER['PHP_AUTH_PW'];
}
mysql_close();
}
//*** Session ***//
if(trim($_SESSION["strUser"])=="" or trim($_SESSION["strPass"])=="")
{
fncAuthentication();
exit();
}
?>
error ที่เจอ
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\pj\selec_staff.php:6) in C:\AppServ\www\pj\phpAuthMySQLCheck.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\pj\selec_staff.php:6) in C:\AppServ\www\pj\phpAuthMySQLCheck.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\pj\selec_staff.php:6) in C:\AppServ\www\pj\phpAuthMySQLCheck.php on line 5
ดาต้าเบสที่เชื่อมต่อ ชื่อ pj ตาราง user
Code (SQL)
ฐานข้อมูล: `pj`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `user`
--
CREATE TABLE `user` (
`id_staff` int(20) NOT NULL auto_increment,
`password` varchar(20) NOT NULL,
`name_staff` varchar(30) NOT NULL,
`lastname_staff` varchar(30) NOT NULL,
`email_staff` varchar(30) NOT NULL,
`tel_staff` varchar(15) NOT NULL,
`user` varchar(20) NOT NULL,
PRIMARY KEY (`id_staff`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- dump ตาราง `user`
--
INSERT INTO `user` VALUES (2, '1111', '1111', '1111', '1111', '1111', '1111');
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\pj\selec_staff.php:6) in C:\AppServ\www\pj\phpAuthMySQLCheck.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\pj\selec_staff.php:6) in C:\AppServ\www\pj\phpAuthMySQLCheck.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\pj\selec_staff.php:6) in C:\AppServ\www\pj\phpAuthMySQLCheck.php on line 5