[英]How redirect without header in php?
我有controllerLoginUsu.php
:
<?php
require "dao/daoLoginUsu.php";
class LoginUsuario{
public function setDatos($aInput) {
$obj = json_decode($aInput, true);
$Dao = new daoLoginUsuario();
$Dao->setDataDato($obj);
$msj = $Dao->setDataDato($obj);
session_start();
if ($msj === 'si') {
$_SESSION['msj'] = "si";
return $msj;
header("http://localhost:8080/formulario_web/formulario/formulario_lazos.php");
exit;
}
}
}
?>
在啟動會話並返回$ msj之后,我需要重定向,但帶有標頭不起作用。 一些其他解決方案?
對不起,我的英語。
如果要重定向而沒有標題,請嘗試以下操作:
echo "<script>";
echo "location.replace('classes.php?add=sucess')";
echo "</script>";
您忘記了位置。
嘗試:
header("Location: http://localhost:8080/formulario_web/formulario/formulario_lazos.php");
您永遠不會到達header()調用:
return $msj; // terminate function IMMEDIATELY
header("http://localhost:8080/formulario_web/formulario/formulario_lazos.php"); // never reached
return
應該在AFTER header()
。
答案實際上是以下兩種方法的混合
如果要發布header()
那么您將不希望return
任何內容,因為您將強制加載新表單。 當然, return
將停止執行此方法,並且在您的情況下,標頭甚至都不會執行。
您也忘記添加location:
header()
語句的一部分。
所以
if ($msj === 'si') {
$_SESSION['msj'] = "si";
header("Location: http://localhost:8080/formulario_web/formulario/formulario_lazos.php");
exit;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.