标头函数中的PHP变量 [英] PHP variable in header function

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

问题描述

我正在尝试使用标头功能通过URL传递变量,以作为重定向页面的一种方式.但是,当页面被重定向时,它将传递实际的变量名称,而不是与变量关联的值.我是PHP的新手,并且不完全了解语法,因此,请您对执行此操作的正确方法作进一步说明.

I am attempting to pass variables through the URL using the header function as a way to redirect the page. But when the page is redirected it passes the actual variable names rather than the values associated with the variables. I am new to PHP and do not fully understand the syntax so any further explanation as to the proper way to do this would be much appreciated.

header('location: index.php?id=".$_POST[ac_id]."&err=".$login."');

推荐答案

您要:

header("Location: index.php?id=".$_POST['ac_id']."&err=".$login);

您在此字符串中组合了'",这就是为什么它无法正确插入变量的原因.在上面的示例中,您严格使用"打开字符串,并将变量与字符串连接.

You were combining ' and " in this string, which is why it couldn't interpolate the variables properly. In my example above, you are strictly opening the string with " and concatenating the variables with the string.

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

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