在$\u GET中使用时,PHP加密和解密不起作用
我正在使用以下代码在$\u GET中使用时,PHP加密和解密不起作用,php,mysql,encryption,base64,md5,Php,Mysql,Encryption,Base64,Md5,我正在使用以下代码 function encryptIt( $q ) { $cryptKey = 'qJB0rGtIn5UB1xG03efyCp'; $qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) ); return( $qEncoded ); } funct
function encryptIt( $q ) {
$cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
$qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
return( $qEncoded );
}
function decryptIt( $q ) {
$cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
$qDecoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
return( $qDecoded );
}
如果我将值存储在$\u会话中,它可以正常工作,但是如果尝试在$\u GET中加密数据,有时它可以工作,有时它不能,让我用下面的代码解释
if(isset($_GET['edit']))
{
$user_id = decryptIt($_GET['edit']);
$errors[] = $user_id;
if(is_numeric($user_id))
{
//set id's to sessions
$session->setValues(md5('agent_user'), encryptIt($get_user->id));
$session->setValues(md5('agent_person'), encryptIt($get_person->id));
$session->setValues(md5('agent_link'), encryptIt($per_add_lnk->id));
$session->setValues(md5('agent_address'), encryptIt($get_address->id));
}else{
$errors[] = "Errors in the id";
//redirect to page
}
}
$errors[]
打印以下内容(它应该是一个数字)
����3&-��*"(��@�S]���{]��^�代码>
$user\u id=decryptIt($\u GET['edit']);
没有按我希望的方式工作不知道原因是什么
顺便说一句,我所有的ID都是int(11)自动递增的,这就是我加密的方式:
<a href="adduser.php?edit=<?php echo encryptIt($user->id); ?>" class="btn btn-xs blue">
您可能需要对输出进行url编码
<a href="adduser.php?edit=<?php echo urlencode(encryptIt($user->id)); ?>" class="btn btn-xs blue">
你能给一个ID举个例子吗?(你在“编辑”中发送的内容的一个例子)@matan7890整数值mysql auto increment ID是唯一的inti如果你使用MD5作为加密的一部分,你可能做错了。+1来详细说明GET字符串中的+
正在被更改为空格字符。great@Musa…正常工作:)我会在20分钟内接受的在那之前我不能这么做