我可以直接以具有GET方法的形式发送编码信息吗?

时间:2014-05-08 22:08:08

标签: javascript php html

我有使用GET方法的html表单,但我想发送的信息并不那么明显。例如,放置简单的base64编码。我需要唯一的URL,因此每次需要相同的信息时,我们都需要具有相同且不那么明显的URL。

示例:

www.mywebsite.com/index.php?myname=johnDoe

但我不需要那么明显:

www.mywebsite.com/index.php?bXluYW1lJTNEam9obkRvZQ==

这是简单的base64加密。

2 个答案:

答案 0 :(得分:2)

GET和POST数据作为关联数组存储在超级全局$_GET$_POST中。您真正需要做的就是使用base64_encode()base64_decode()方法。唯一的问题是你不能在数组上调用这些方法,但你可以在字符串上调用它。这就是json_encode()json_decode()发挥作用的地方。

$array   = array('one' => 1, 'two' => 2); // substitute $_GET or $_POST here 
$json    = json_encode($array);
$string  = base64_encode($json);

echo $string; // this is the base64-encoded string

$json    = base64_decode($string);
$array   = json_decode($json);

print_r($array); // this is an associative array

您可以将表单GET或POST转换为转换器页面,该页面将POST或GET数组转换为base64编码的字符串,然后使用header()重定向到需要特殊URL的页面。

然后,接收页面可以反转该过程以从表单中获取输入。

答案 1 :(得分:0)

在对查询字符串进行编码后,根据您在问题中准备的内容,可以在index.php

的php端执行此操作
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"];
$url_array = parse_url($url);
$encodedURL = $url_array['query'];
$decodeURL = base64_decode($encodedURL);