[英]PHP if(cookie is set Redirect loop
所以,我在使用非常簡單的 PHP 時遇到了麻煩,因為我不擅長使用它。 所以這是代碼:
<?php
if(!isset ($_COOKIE['cookie'])) {
header("Location: index.html");
} else {
header("Location: index2.php");
?>
它位於 HTML 文檔的頂部,在任何其他 HTML 之前,因為我聽說 header 無法正常工作(該聲明本身可以證明我的無知)。 但基本上,我有一個您必須同意才能繼續訪問該站點的協議頁面,但它不被視為我的索引文件。 所以我需要這個重定向來檢測由 agreement.php 設置的 cookie 是否存在,我假設這個語法是正確的,但它似乎不起作用。 我用了一個回聲“
關於如何修復的任何想法? 先感謝您。
嘗試使用此代碼:
index.php 應該是這個(文件開始到結束)
<?php
if (!isset($_COOKIE['cookie']))
{
header('Location: http://www.example.com/index2.php');
exit;
}
?>
<!DOCTYPE html>
...rest of your HTML code
您還缺少 else 上的右花括號
<?php
if(!isset ($_COOKIE['cookie']))
{
header("Location: index.html");
}
else
{
header("Location: index2.php");
}
?>
我寧願使用這些方面的東西
<?php
echo $htmlHeader;
while($stuff){
echo $stuff;
}
echo "<script>window.location = 'url'</script>";
?>
它對我很好用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.