Php 将$放入变量或放入URL

Php 将$放入变量或放入URL,php,Php,如何放置$_GET['**'];转换为字符串或将其转换为变量。 例如,我有一个url: 我想从url中获取区域和休息id。以便将另一个页面重定向到此页面 echo"<script>window.open('product_page.php?rest_id= 'put get here'/area='put get here'','_self')</script>"; 这显然不起作用,所以我的问题是如何使2$\u进入变量或调用$\u进入re direct字符串 到目前为

如何放置$_GET['**'];转换为字符串或将其转换为变量。 例如,我有一个url:

我想从url中获取区域和休息id。以便将另一个页面重定向到此页面

echo"<script>window.open('product_page.php?rest_id= 'put get here'/area='put get here'','_self')</script>";
这显然不起作用,所以我的问题是如何使2$\u进入变量或调用$\u进入re direct字符串

到目前为止我累了什么

echo"<script>window.open('product_page.php?rest_id=' . $GET['rest_id'] . '/area='put get here'','_self')</script>";
echo“window.open('product\u page.php?rest\u id='。$GET['rest\u id']。/area='put GET here','u self');

最佳实践是如何或怎样的?

好的,首先要做的事。在URL中,您必须使用符号“&”分隔参数,如下所示

http://localhost/PhpProject2/product_page.php?rest_id=3&area=Enfield
$rest_id = $_GET['rest_id'];
此外,您必须将$\u GET值分配给变量,而不是相反,如下所示

http://localhost/PhpProject2/product_page.php?rest_id=3&area=Enfield
$rest_id = $_GET['rest_id'];
因此,如果您创建一个名为
product_page.PHP
的PHP文件,并使用我提供的url,并且您的PHP代码如下所示,它应该可以工作

<?php
if (isset($_GET['rest_id'])){
    $rest_id = $_GET['rest_id'];
}

if (isset($_GET['rest_id'])){
    $area = $_GET['area'];
}

$url = 'other_page.php?rest_id=' . $rest_id . '&area=' . $area;
header("Location: $url");
?>


这里的问题是,为什么要从这个页面重定向到另一个页面,而不直接将参数发送到“other_page.php”?

您的查询字符串使用了错误的分隔符。它应该是
http://localhost/PhpProject2/product_page.php?rest_id=3&area=Enfield
。我有一辆微型购物车。因此,在将项目添加到购物车时,用户会被发送到shopping_cart.php?添加项目=“项目编号”。因此,在购物车页面上添加商品后,我需要重定向回正确的产品页面oohh。。好啊好。。如果这是您的解决方案,请不要忘记将其标记为正确答案!除息的