我可以直接在具有GET方法的表单中发送编码信息吗?


Can I directly send encoded information's in forms that have GET method?

我有html表单,使用GET方法,但我想发送信息不那么明显。比如放简单的base64编码。我需要唯一的URL,所以每次需要相同的信息,我们需要有相同的,不那么明显的URL。

的例子:

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

但我不需要这么明显:

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

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的页面。

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

在对查询字符串进行编码后,根据您在问题中准备的内容,您可以在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);