这是我的PHP代码,我将一些数据以加密形式传递给url。
<?php
$cancel = encrypt($_GET['id'] . '|' . hotel($_GET['id'], 'area') . '|' . $_GET['roomid']);
<input type = "hidden" name = "cancel_return" value = "<?php echo ROOT_URL; ?>/canceled.php?data=<?php echo $cancel;?>" >
这是我获取网址数据的下一页:
$custom_decrypt = $_GET['data'];
$res = decrypt($custom_decrypt);
print_r( $res);
此加密和解密代码:
function encrypt($text){
$salt = 'DFS65'; $key = md5($salt);
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key, $text, MCRYPT_MODE_CBC, md5($key));
$encrypted = base64_encode($encrypted); return $encrypted;
}
function decrypt($text) {
$salt = 'DFS65';
$key = md5($salt);
$data = base64_decode($text);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key, $data, MCRYPT_MODE_CBC, md5($key));
$decrypted = rtrim($decrypted, "\0"); return $decrypted;
}
但我得到了解密结果:
3 =E j F 1tt 43a_ŋQ4
答案 0 :(得分:0)
You errors:
?>
input
值标记action
form
参数中
input
名称参数这是你固定的代码。它已被修改以进行调试,因此请检查并根据您的需要进行更新
<强>的index.php:强>
<?php
$_GET['id'] = '1';
$_GET['roomid'] = '2';
function encrypt($text){
$salt = 'DFS65'; $key = md5($salt);
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key, $text, MCRYPT_MODE_CBC, md5($key));
$encrypted = base64_encode($encrypted); return $encrypted;
}
function decrypt($text) {
$salt = 'DFS65';
$key = md5($salt);
$data = base64_decode($text);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key, $data, MCRYPT_MODE_CBC, md5($key));
$decrypted = rtrim($decrypted, "\0"); return $decrypted;
}
?>
<?php $cancel = encrypt($_GET['id']. '|'. $_GET['roomid']);?>
<form action="/canceled.php" method="get">
<input type="input" readonly="readonly" name="data" value="<?php echo $cancel;?>">
<input type="submit" >
</form>
和cancel.php
<?php
function encrypt($text){
$salt = 'DFS65'; $key = md5($salt);
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key, $text, MCRYPT_MODE_CBC, md5($key));
$encrypted = base64_encode($encrypted); return $encrypted;
}
function decrypt($text) {
$salt = 'DFS65';
$key = md5($salt);
$data = base64_decode($text);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key, $data, MCRYPT_MODE_CBC, md5($key));
$decrypted = rtrim($decrypted, "\0"); return $decrypted;
}
$custom_decrypt = $_GET['data'];
$res = decrypt($custom_decrypt);
print_r($res);
<强>输出:强>
1|2
答案 1 :(得分:0)
看看你的意见:
<input type="hidden" name="cancel_return" value=".......">
输入字段名称为cancel_return
,但在服务器上您尝试获取未设置的属性:
$custom_decrypt = $_GET['data'];
实际应该是:
$custom_decrypt = $_GET['cancel_return'];
此($_GET['cancel_return']
)将返回加密值。然后,您可以解密该值并使用parse_url从解密的URL中的查询中获取data
值。
$cancel_return = $_GET['cancel_return']; // Get the CORRECT value sent from the client
$cancel_return_url = parse_url($cancel_return); // Parse the URL that was passed to the server and return its components
parse_str($cancel_return_url['query'], $cancel_return_query); // Parse the parameters of the query string of the url
echo decrypt($cancel_return_query['data']); // decrypt the 'data' parameter of the query string