[英]Cannot modify header information - headers already sent - PHP MVC : Redirect from one controller to another controller
我正在尝试学习 MVC 框架并尝试创建一个简单的登录系统,但我收到有关标题的错误。
警告:无法修改 header 信息 - 已发送的标头(输出开始于 /home/jobspeci/public_html/gerome/clisys/pg_view/login.php:1)在 /home/jobspeci/public_main/gerome/clisys/pg_controller/ php 上线 41
一旦用户输入与用户匹配并通过,目标是重定向或加载另一个 controller。 基本上是显示主页。
public function login(){
if (isset($_POST['btnLogin'])){
$user = addslashes(strip_tags($_POST['username'])) ;
$pass = addslashes(strip_tags($_POST['password'])) ;
$data = $this->Main->mainModel_getUserData($user,$pass);
if ($data['RESULT'] == 'SUCCESS'){
//LOAD LANDING PAGE
$location = BASEURL . SYS_DIR. "/registration"; // sample output for testing // page should redirect to this
header("$location");
exit();
}else{
//show error message
}
}
}
model class 中的方法
public function mainModel_getUserData($username, $password){
$sql = "Select * from `" .DB_CNC."`.`".DB_TABLE . "` where username = '$username' and password = '$password'";
$result = $this->CN->Q($sql);
$data = array();
if ($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
if ($username == $row[USERNAME] AND $password == $row[PASSWORD]){
$data['RESULT'] = "SUCCESS";
return $data;
}
}
}
$data['RESULT'] = "";
return $data;
}
页面预览:
<form name = "login" method="POST" class="system-module" path="<?php echo ASSETPATH;?>" dir="<?php echo SYS_DIR?>">
<div class="container">
<label>Username : </label>
<input type="text" placeholder="Username" name="username" required>
<br>
<label>Password : </label>
<input type="password" placeholder="Password" name="password" required>
<br>
<button type="submit" value="Login" name="btnLogin"> Login</button>
<br>
<span style="text-align:center">No account yet? <a name="register" href="registration"> create one </a></span>
</div>
</form>
我正在尝试学习 MVC 框架并尝试创建一个简单的登录系统,但我收到有关标题的错误。
警告:无法修改 header 信息 - 已发送的标头(输出开始于 /home/jobspeci/public_html/gerome/clisys/pg_view/login.php:1)在 /home/jobspeci/public_main/gerome/clisys/pg_controller/ php 上线 41
一旦用户输入与用户匹配并通过,目标是重定向或加载另一个 controller。 基本上是显示主页。
public function login(){
if (isset($_POST['btnLogin'])){
$user = addslashes(strip_tags($_POST['username'])) ;
$pass = addslashes(strip_tags($_POST['password'])) ;
$data = $this->Main->mainModel_getUserData($user,$pass);
if ($data['RESULT'] == 'SUCCESS'){
//LOAD LANDING PAGE
$location = BASEURL . SYS_DIR. "/registration"; // sample output for testing // page should redirect to this
header("$location");
exit();
}else{
//show error message
}
}
}
model class 中的方法
public function mainModel_getUserData($username, $password){
$sql = "Select * from `" .DB_CNC."`.`".DB_TABLE . "` where username = '$username' and password = '$password'";
$result = $this->CN->Q($sql);
$data = array();
if ($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
if ($username == $row[USERNAME] AND $password == $row[PASSWORD]){
$data['RESULT'] = "SUCCESS";
return $data;
}
}
}
$data['RESULT'] = "";
return $data;
}
页面预览:
<form name = "login" method="POST" class="system-module" path="<?php echo ASSETPATH;?>" dir="<?php echo SYS_DIR?>">
<div class="container">
<label>Username : </label>
<input type="text" placeholder="Username" name="username" required>
<br>
<label>Password : </label>
<input type="password" placeholder="Password" name="password" required>
<br>
<button type="submit" value="Login" name="btnLogin"> Login</button>
<br>
<span style="text-align:center">No account yet? <a name="register" href="registration"> create one </a></span>
</div>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.