[英]PHP passing a variable with header redirect
我正在嘗試在 header 鏈接中傳遞一個變量。 我試過下面的代碼
$name = "mike";
if($name != "lopan"){
header("Location:error-page.php?$errorMssg=Please enter information?");
}
此頁面重定向到位置但不傳遞包含消息的變量。 但是當我用這樣的值創建一個簡單的鏈接時:
<a href="error-page.php?$errorMssg=so what happened there buddy?">link</a>
它通過它就好了。
任何想法我做錯了什么? 或者我不能傳遞帶有標題的信息?
您需要像這樣使用urlencode :
if($name != "lopan"){
header("Location:error-page.php?errorMssg=".urlencode("Waoo so your not EVEN going to try to enter information huh?"));
}
在 error-page.php 中,你應該得到它(不需要 urldecode):
<?php
$errorMssg = $_GET['errorMssg'];
刪除errorMssg
之前的$
並對消息進行urlencode
。
可能是因為你有$errorMssg
而不是$errorMsg
嗎? 也嘗試制作一個有效的 url,例如將“”替換為 %20 等,function urlencode()
可以幫助您解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.