php 地址 变量

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:09:07
我想将以下网页
http://localhost/main.php?id=1&kw=wearehere
传递到http://localhost/login.php?from=http://localhost/main.php?id=1&kw=wearehere
要保留后面的变量
请问应该怎么写这段代码?
主要是我无法知道?后面的变量?id=1&kw=wearehere,问如何获得

记得将查询字符串做base64编码。。。。

$a = 'http://localhost/main.php?id=1&kw=wearehere';
$b = 'http://localhost/login.php?from=';
$b .= rawurlencode($a);

header("Location: $b");
exit();

楼上的。 不用base64吧。。
用 urlencode()函数就可以了。
譬如:
$url = urlencode('http://localhost/main.php?id=1&kw=wearehere');
$new_url = "http://localhost/login.php?from=$url";

在login.php里面要这样取就可以了:
$from_url = urldecode($_GET['from']);

$a=$_GET['from'];
$url=explode("?",$a);
print_r($url);