这是我的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;?>" >
这是我获取URL数据的下一页:
$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
You errors:
- 第一行缺少 php 脚本的 php 关闭标记
?>
- 值应通过
input
值标记传递 - 接收器文件 URL 应位于
action
参数中form
- var 的名称应通过
input
name 参数传递
这是固定代码。它已针对调试进行了修改,因此请检查它并根据您的需要进行更新
索引.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>
并取消.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
看看你的输入:
<input type="hidden" name="cancel_return" value=".......">
输入字段名称为 cancel_return
,但在服务器上,您尝试获取 unset 属性:
$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