mysql - PHP Encryption and decryption is not working when using in $_GET -


i'm using following code

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 ); } 

it works fine if store value in $_session if try , encrypt data in $_get works doesn't, let me explain code below

if(isset($_get['edit'])) {     $user_id  = decryptit($_get['edit']);     $errors[] = $user_id;         if(is_numeric($user_id))         {             //set id's 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 id";         //redirect page     } } 

the $errors[] prints following instead (it should number)

����3&-��*"(��@�s]���{]��^�

that $user_id = decryptit($_get['edit']); not work way want work dont know reason

btw id's int(11) auto-increment , how encrypting:

<a href="adduser.php?edit=<?php echo encryptit($user->id); ?>" class="btn btn-xs blue"> 

output : adduser.php?edit=jy3e+ulsn8+yhgzlxqx5woa2j53xnbvyyzfr+9tklyq=

don't i'm doing wrong , where.

any idea? please help.

you need url encode output

<a href="adduser.php?edit=<?php echo urlencode(encryptit($user->id)); ?>" class="btn btn-xs blue"> 

charters +, = generated base64 encoding has special meaning in urls.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -