我正在嘗試使用核心 PHP 在 WordPress 中創建一個簡單的登錄系統,但我收到此錯誤訊息
警告:無法修改標頭資訊 - 標頭已由 /www/www/www/wp-content/themes/ 中的 /www/www/www/wp-content/themes/mytheme/header.php:20 開始發送第 9 行的 mytheme/page-solutions.php
在header.php
我的模板中
<?php
session_start();
/**
* The header.
*
*/
?>
<!doctype html>
<html lang="en">
<head>
...
并在page-solutions.php
頁面中
<?php
/**
* Template Name: Solutions
*
*/
get_header();
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: home");
exit;
}
如您所見,我正在嘗試將未登錄的用戶重定向到front-page.php
我稱之為 Home 但我收到錯誤header("location: home");
您能告訴我如何解決這個問題嗎?
uj5u.com熱心網友回復:
必須在進行任何輸出之前呼叫修改標頭的函式。在這種情況下,您正在呼叫發送輸出的 get_header() 函式,然后您嘗試修改標頭。嘗試更改執行代碼的順序,如下所示:
<?php
/**
* Template Name: Solutions
*
*/
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: home");
exit;
}
get_header();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/493801.html