php - codeigniter url encrypt not working -
<a href="<?php echo base_url().'daily_report/index/'.$this->encrypt->encode($this->session->userdata('employee_id')) ?>">
i have encrypted above url using codeigniter encrypt set encryption key in codeigniter config file
$config['encryption_key'] = 'giouetfdwgzbl2bje9bx5b0rlsd0gkdv';
and called in autoload
$autoload['libraries'] = array('session','form_validation','encrypt','encryption','database');
when ulr(href) load url this
http://localhost/hrms/daily_report/index/fvjgcz4qqztqak0jaomjiafbz/vkvsbug1igpqekqcz/k7+wue4e/m9u1ejwh3uktkeihexjgkk1dj2awl0+zq==
but url not decoded, , i;m not getting employee_id shows empty.
public function index($employee_id) { $save_employee_id = $employee_id; // decoding encrypted employee id $get_employee_id = $this->encrypt->decode($save_employee_id); echo $employee_id; // answer: fvjgcz4qqztqak0jaomjiafbz echo "<br>"; echo $get_employee_id; // display null echo "<br>"; exit(); // employee daily report $data['get_ind_report'] = $this->daily_report_model->get_ind_report($get_employee_id); // daily report page $data['header'] = "daily report"; $data['sub_header'] = "all"; $data['main_content'] = "daily_report/list"; $this->load->view('employeelayout/main',$data); }
complete url(3) is
fvjgcz4qqztqak0jaomjiafbz/vkvsbug1igpqekqcz/k7+wue4e/m9u1ejwh3uktkeihexjgkk1dj2awl0+zq==
it shows only
fvjgcz4qqztqak0jaomjiafbz
i tried change in the
$config['permitted_uri_chars'] = 'a-za-z 0-9~%.:_\-@=+';
by / in permitted uri chars throwing error so, need encryption $id in url using codeigniter encrypt class , decrypt in server side actual $id, fetch data db. appreciated
you have extend encryption class , avoid /
working. place class in application/libraries
folder. , name my_encrypt.php
.
class my_encrypt extends ci_encrypt { /** * encodes string. * * @param string $string string encrypt. * @param string $key[optional] key encrypt with. * @param bool $url_safe[optional] specifies whether or not * returned string should url-safe. * @return string */ function encode($string, $key="", $url_safe=true) { $ret = parent::encode($string, $key); if ($url_safe) { $ret = strtr( $ret, array( '+' => '.', '=' => '-', '/' => '~' ) ); } return $ret; } /** * decodes given string. * * @access public * @param string $string encrypted string decrypt. * @param string $key[optional] key use decryption. * @return string */ function decode($string, $key="") { $string = strtr( $string, array( '.' => '+', '-' => '=', '~' => '/' ) ); return parent::decode($string, $key); } }