簡體   English   中英

$ variable =標題位置

[英]$variable = header location

我可以找到數百個“插入標題位置”的例子,但我還沒有找到任何$variable = header位置的例子。

這可能嗎:

$error=header('Location: http://www.example.com/error.php');

基本上,如果在mysql中找不到行,我有3個條件。

所以我設置了3個條件:

if condition1 $ error =“a statement”

if condition2 $ error =“SELECT data FROM table WHERE data ='default'”;

if condition3 $ error = header('Location:example.com/error.php');

然后if($ result-> num_rows = 0)$ error

在我的情況下, $error可能是3個不同的東西,其中一個是“重定向到錯誤頁面”但是$error=header('Location:blah'); 導致500服務器錯誤。

我改變了我的代碼,以便我可以以傳統方式使用標題位置,但仍然想知道$var = header位置是否可行。

提示問題的原始代碼已被覆蓋,我不再需要發布。

謝謝湯姆

標題返回void類型。 除了null之外,你不能指望$error

如果您收到500錯誤,則是由其他原因引起的(語法錯誤?)。

http://php.net/manual/de/function.header.php

header()返回void,因此,您可以編寫$error=header('Location: http://www.example.com/error.php'); ,但它不會做太多。

header('Location: ...'); 你應該叫exit;

你不能將'header'函數賦給任何東西,因為它總是會返回void。 有點無用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM