【问题标题】:Encode/Decode not always working - Codeigniter编码/解码并不总是有效 - Codeigniter
【发布时间】:2015-03-04 02:33:10
【问题描述】:

我有一个从数据库中删除的删除按钮。我按下页面上的删除按钮,它不会做任何事情,直到我按下它几次。有时,它只是一次尝试从数据库中删除值,而其他时候,我必须多次按下删除按钮才能将其删除。有什么办法可以克服吗?

我的视图文件:

//other code above

<?php $encrypted = $this->encrypt->encode($data->pid); ?>
<a href="<?php echo base_url() . "profile/delete_entry/" .  $encrypted; ?>">Delete</a>

//other code below

我的控制器:

$this->load->model('model_entry');

    $pid = $this->uri->segment(3);

    $result = $this->model_entry->entry_delete($pid);
    //redirect to entries index.php

我的模特

public function entry_delete($pid) {

    $pid = $this->encrypt->decode($pid); //to decode

    $uid=$this->session->userdata('uid');

    $whereConditions = array('pid' => $pid, 'uid' => $uid);
    $this->db->where($whereConditions);

    $this->db->delete('dayone_entries');
}

【问题讨论】:

标签: php database codeigniter


【解决方案1】:

不确定是否可以在 URL 中放置加密数据。 Codeigniter 不允许您使用带有特殊字符(如“=”)的 URL。据我所知,如果您执行 $encrypted = $this-&gt;encrypt-&gt;encode($data-&gt;pid); 之类的操作,它将返回一个结尾带有双 '=' 的字符串。

这里是关于 CodeIgniter 中加密的解释。 Encryption string on Codeigniter

【讨论】:

  • 我的 config.php 中有这个:$config['permitted_uri_chars'] = '+=\a-z 0-9~%.:_-'; 那么最好的方法是什么?谢谢
  • 你有同样的问题吗?
  • 是的,终于同意@TaylorSwift,在 allowed_uri_chars 中添加 '='
  • 我做到了。而且我必须按几次删除按钮才能删除它。
  • 哦,我想我明白了..只需检查您的加密数据,是否有'/'?如果该字符存在,您的$pid = $this-&gt;uri-&gt;segment(3); 将无法获得完整的加密数据
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
  • 2018-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-17
  • 2021-09-09
相关资源
最近更新 更多