带有参数的PHP标头位置 [英] PHP Header Location with parameter

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

问题描述

是否可以将参数附加到PHP标头位置?我无法让它工作。实际上是否允许这种语法?

Is it possible to append a parameter to a PHP Header Location? I'm having trouble getting it to work. Is this syntax actually allowed?

$qry = $_SERVER['QUERY_STRING'];
header('Location: http://localhost/blast/v2/?$qry ') ;

它只是不会用它的实际值替换$ qry ....为什么??

it just won't replace $qry wit its actual value....why??

在浏览器中它看起来像这样:

in the browser it ends up looking like this:

http:// localhost / blast / v2 / ?$ qry

谢谢

推荐答案

将单引号更改为双引号:

Change the single quotes to double quotes:

header("Location: http://localhost/blast/v2/?$qry");

PHP中的单引号字符串被视为字符串文字,未解析变量。为变量解析双引号字符串 ,因此您将获得 $ qry 包含附加内容,而不是字面上 $ qry

A single quoted string in PHP is treated as a string literal, which is not parsed for variables. Double quoted strings are parsed for variables, so you will get whatever $qry contains appended, instead of literally $qry.

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

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