weixin_33743703 2019-07-19 07:00 采纳率: 0%
浏览 552

使用Ajax进行URL加密

I want to encrypt assignment_id in url which retrived on ajax table

<a href="<?php echo base_url()?>index.php/Welcome/quotation_detailed?assignment_id='+data[i].assignment_id+'" class="btn btn-success btn-sm item_edit" data-assignment_id="'+data[i].assignment_id+'">'+data[i].assignment_id+'</a>
  • 写回答

2条回答 默认 最新

  • derek5. 2019-07-19 07:29
    关注

    There are indeed possibilities to achieve what you want - here is a step by step guide

    1. Read the docs - CI provides an encryption library - take a look here - and define the generated key as described in your config.php

    2. create a helper in your application/helpers folder, call it encryption_helper.php and put the following functions in

      function ci_encode($str_to_encode) {
          $CI = get_instance();
      
          if (!empty($str_to_encode)) {
              return bin2hex($CI->encryption->encrypt($str_to_encode));
          }
          return $str_to_encode;
      }
      
      function ci_decode($str_to_decode) {
          $CI = get_instance();
          return $CI->encryption->decrypt(pack('H*', $str_to_decode));
      }
      
    3. Go to your autoload.php in your application/config folder and autoload the library and the helper. Something like $autoload['libraries'] = array(...,'encryption'); and $autoload['helper'] = array(...,'encryption_helper'); should work

    4. now you can encode / decode whatever you want - based on your example:

      <a href="<?php echo base_url();?>Admin/assignments_detailed?assignment_id=<?php echo ci_encode($row->assignment_id) ?>"><?php echo $row->assignment_id; ?></a>
      

      and decoding

      echo ci_decode($this->input->get('assignment_id');
      

    But keep in mind - the main problem is that you try to obfuscate some information which should never be obfuscated - in the end it is your responsibility to handle data properly - even if some user tries to manipulate it

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题