PHP通过标头重定向传递变量 [英] PHP passing a variable with header redirect

查看:76
本文介绍了PHP通过标头重定向传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在标头链接中传递变量.我尝试了下面的代码

I am trying to pass a variable within a header link. I have tried below code

$name = "mike";

if($name != "lopan"){
        header("Location:error-page.php?$errorMssg=Please enter information?");
}

此页面重定向到位置,但未传递包含消息的变量.但是,当我用这样的值创建一个简单的链接时:

This page redirect to location but doesn't pass the variable that contains the message. But when i create a simple link with values like this:

<a href="error-page.php?$errorMssg=so what happened there buddy?">link</a>

它通过就可以了.

有什么主意我做错了吗?还是我无法通过标题传递信息?

Any ideas what i am doing wrong? or i can not pass information with headers?

推荐答案

您需要使用 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):

And in error-page.php, you should get it (no need to urldecode):

<?php
$errorMssg = $_GET['errorMssg'];

这篇关于PHP通过标头重定向传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆