PHP beginner |
|
Hallo,
ik ben bezig met een help-systeem te maken voor mijn website, en ben nu bezig met het administratiegedeelte.
Ik heb echter een probleem met de foutmelding "headers already sent", met telkens een verwijzing naar de lijn waarop "header('Location: ...');" staat.
Dit is mijn code:
auth.php
<?php
include_once('main.class.php');
class auth extends main {
function __construct() {
parent::__construct();
if($this->dbc_conn_error_bool == true):
exit();
endif;
@session_start();
}
public function login($emailadress,$password,$language) {
$q = "
SELECT
id
FROM
admin_user
WHERE
email = '".$emailaddress."'
AND
password = '".$password."'
";
$r = mysqli_query($this->dbc,$q);
if(mysqli_num_rows($r) == 1):
$data = mysqli_fetch_array($r,MYSQLI_ASSOC);
$_SESSION['auth_admin'] = $data['id'];
$_SESSION['auth_admin_time'] = mktime() + 300;
header('Location: /help/'.$language.'/admin/main');
else:
header('Location: /help/'.$language.'/admin/login');
endif;
}
public function authenticate($language) {
if(isset($_SESSION['auth_admin']) && $_SESSION['auth_admin_time'] > mktime()):
$_SESSION['auth_admin_time'] = mktime() + 300;
else:
session_unset($_SESSION['auth_admin']);
session_unset($_SESSION['auth_admin_time']);
session_destroy();
header('Location: /help/'.$language.'/admin/login');
endif;
}
public function logout($lang) {
session_unset($_SESSION['auth_admin']);
session_unset($_SESSION['auth_admin_time']);
session_destroy();
header('Location: /help/'.$language.'/admin/login');
}
}
?>
<?php include_once('main.class.php'); class auth extends main { function __construct() { parent::__construct(); if($this->dbc_conn_error_bool == true): endif; } public function login($emailadress,$password,$language) { $q = " SELECT id FROM admin_user WHERE email = '".$emailaddress."' AND password = '".$password."' "; $r = mysqli_query($this->dbc,$q); if(mysqli_num_rows($r) == 1): $data = mysqli_fetch_array($r,MYSQLI_ASSOC); $_SESSION['auth_admin'] = $data['id']; $_SESSION['auth_admin_time'] = mktime() + 300; header('Location: /help/'.$language.'/admin/main'); else: header('Location: /help/'.$language.'/admin/login'); endif; } public function authenticate($language) { if(isset($_SESSION['auth_admin']) && $_SESSION['auth_admin_time'] > mktime()): $_SESSION['auth_admin_time'] = mktime() + 300; else: header('Location: /help/'.$language.'/admin/login'); endif; } public function logout($lang) { header('Location: /help/'.$language.'/admin/login'); } } ?>
in de klasse main wordt enkel de database-verbinding gemaakt, niets ge-echoëd of geprint ofzo.
login.php
<?php
session_start();
include_once('class/auth.class.php');
if(isset($_SESSION['auth_admin'])):
header('Location: http://www.hbvl.be/');
endif;
$auth = new auth;
if(isset($_POST['submit'])) {
$emailaddress = $_POST['emailaddress'];
$password = $_POST['password'];
$auth->login($emailaddress,$password,$_GET['lang']);
}
switch ($_GET['lang']) {
case nl:
include_once('../lang/dutch.lang.php');
break;
case en:
include_once('../lang/english.lang.php');
break;
default:
include_once('../lang/dutch.lang.php');
break;
}
?>
<!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=utf-8" />
<meta name="keywords" content="netraze,help" />
<meta name="author" content="Netraze" />
<title>Netraze - <?php echo $txt['help']['title']; ?></title>
<!-- CSS -->
<link rel="stylesheet" href="/help/CSS/base.css" type="text/css" />
<!-- CSS -->
<script type="text/javascript">
function setLang(language) {
window.location = '/help/' + language + '/admin/';
}
</script>
</head>
<body>
<div id="header">
<img src="/icon.png" />
<div id="user"><?php echo $txt['help']['title']; ?></div>
<div id="menu">
<a href="/help/<?php echo $_GET['lang']; ?>/admin/" class="menuitem_selected"><?php echo $txt['help']['admin_login']['login']; ?></a>
</div>
<div id="pagetitle"><?php echo $txt['help']['title']; ?></div>
</div>
<div id="content">
<h1><img src="/pen.png" align="absmiddle"/> <?php echo $txt['help']['admin_login']['title']; ?></h1>
<p><?php echo $txt['help']['admin_login']['text']; ?></p>
<form id="admin_login" name="admin_login" action="" method="post">
<label><?php echo $txt['help']['admin_login']['username']; ?>:</label>
<input type="text" id="emailaddress" name="emailaddress" /><br />
<label><?php echo $txt['help']['admin_login']['password']; ?>:</label>
<input type="password" id="password" name="password" /><br />
<label></label>
<input type="submit" id="submit" name="submit" value="<?php echo $txt['help']['admin_login']['submit']; ?>" />
</form>
</div>
<div id="lang">
<h4><?php echo $txt['help']['language']; ?>:</h4>
<select class="lang_select" onchange="setLang(this.value);">
<option value="<?php echo $_GET['lang']; ?>"><?php echo $txt['help']['select_language']; ?></option>
<option value="<?php echo $_GET['lang']; ?>"></option>
<option value="nl">Nederlands</option>
<option value="en">English</option>
</select>
</div>
</body>
</html>
<?php include_once('class/auth.class.php'); if(isset($_SESSION['auth_admin'])): header('Location: http://www.hbvl.be/'); endif; $auth = new auth; if(isset($_POST['submit'])) { $emailaddress = $_POST['emailaddress']; $password = $_POST['password']; $auth->login($emailaddress,$password,$_GET['lang']); } switch ($_GET['lang']) { case nl: include_once('../lang/dutch.lang.php'); break; case en: include_once('../lang/english.lang.php'); break; default: include_once('../lang/dutch.lang.php'); break; } ?> <!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=utf-8" /> <meta name="keywords" content="netraze,help" /> <meta name="author" content="Netraze" /> <title>Netraze - <?php echo $txt['help']['title']; ?></title> <!-- CSS --> <link rel="stylesheet" href="/help/CSS/base.css" type="text/css" /> <!-- CSS --> <script type="text/javascript"> function setLang(language) { window.location = '/help/' + language + '/admin/'; } </script> </head> <body> <div id="header"> <img src="/icon.png" /> <div id="user"> <?php echo $txt['help']['title']; ?></div> <div id="menu"> <a href="/help/ <?php echo $_GET['lang']; ?>/admin/" class="menuitem_selected"> <?php echo $txt['help']['admin_login']['login']; ?></a> </div> <div id="pagetitle"> <?php echo $txt['help']['title']; ?></div> </div> <div id="content"> <h1><img src="/pen.png" align="absmiddle"/> <?php echo $txt['help']['admin_login']['title']; ?></h1> <p> <?php echo $txt['help']['admin_login']['text']; ?></p> <form id="admin_login" name="admin_login" action="" method="post"> <label> <?php echo $txt['help']['admin_login']['username']; ?>:</label> <input type="text" id="emailaddress" name="emailaddress" /><br /> <label> <?php echo $txt['help']['admin_login']['password']; ?>:</label> <input type="password" id="password" name="password" /><br /> <label></label> <input type="submit" id="submit" name="submit" value=" <?php echo $txt['help']['admin_login']['submit']; ?>" /> </form> </div> <div id="lang"> <h4> <?php echo $txt['help']['language']; ?>:</h4> <select class="lang_select" onchange="setLang(this.value);"> <option value=" <?php echo $_GET['lang']; ?>"> <?php echo $txt['help']['select_language']; ?></option> <option value=" <?php echo $_GET['lang']; ?>"></option> <option value="nl">Nederlands</option> <option value="en">English</option> </select> </div> </body> </html>
iemand een idee?
|