使$ _GET变量或放入URL
问题描述:
如何放置$ _GET ['****'];转换成一个字符串或将其变成一个变量。 例如我有这个网址:
http://localhost/PhpProject2/product_page.php?rest_id=3/area=Enfield。
我想从url中获取区域和rest_id。以便将另一个页面重定向到该确切页面。
echo"<script>window.open('product_page.php?rest_id= 'put get here'/area='put get here'','_self')</script>";
我迄今所做的:
if(isset($_GET['rest_id'])){
if(isset($_GET['rest_city'])){
$_GET['rest_id'] = $rest_id;
}
}
这显然是不行的,所以我的问题是如何让我的2 $ _GET到一个变量或致电$ _GET进入复试 - 直接字符串。
什么,我已经厌倦了迄今为止
echo"<script>window.open('product_page.php?rest_id=' . $GET['rest_id'] . '/area='put get here'','_self')</script>";
如何或什么是最好的做法是什么?
答
好的,第一件事情第一。在您的网址您必须使用符号“&”也来分隔参数,这样
http://localhost/PhpProject2/product_page.php?rest_id=3&area=Enfield
,你必须指定$ _GET值的变量,而不是其他的方式,这样
$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'。 –