【问题标题】:How to bypass Disallowed Key Characters in CodeIgniter如何绕过 CodeIgniter 中不允许的键字符
【发布时间】:2015-04-16 08:07:45
【问题描述】:

我在 CodeIgniter 中的 Disallowed Key Characters 中找到解决方案时遇到了这个问题。我的问题是,我希望 £ 符号将通过我的网址传递。

例如,

  • 我有这个产品testing-product-nutella
  • 我想在testing-product-nutella£ 之外添加一个£ 符号,有点像这样。 下面是我的代码

//--------------------------------------------- ------------------------------------// //--------------------------> 建立产品列表数据---------------- ----------// //------------------------------------------------ ---------------------------------//

        $prod_list              = Array();

        foreach($prods_query as $prod)
        {
            //echo htmlentities($prod['prod_name']);
            //print_r($prod);

            //$prod_name_url        = Make_into_url($prod['prod_name']);
            $prod_name_url      = htmlentities($prod['prod_name']);
            print_r($prod_name_url);

            // get the minimum order quantity and price from db
            if ($min_price = $this->Price_model->Get_listing_price($prod['prod_id']))
            {
                $min_order_qty      = $min_price['qty_value'];
                $min_order_price    = $min_price['price_amount'] > 0 ? number_format($min_price['price_amount'], 2) : false;
            }
            else
            {
                // this shouldn't happen but just in case...
                $min_order_qty      = "";
                $min_order_price    = "";
            }

            // get the default image for the product from the database
            $default_pic_row        = $this->Picture_model->Get_default_product_picture($prod['prod_id']);

            // get a list of all the special categories that a product is in
            $product_spec_cats      = $this->Special_category_model->Get_product_special_cats($prod['prod_id']);

            // is the product on special offer, if so, get the details
            $product_spec_off       = $this->Special_offer_model->Get_product_special_offer_details($prod['prod_id']);



            $nameUrl = urlencode($prod_name_url);
            echo "<pre>";
            echo $nameUrl;
            echo "</pre>";

            $prod_list[]            = Array(
                                            "prod_id"           => $prod['prod_id']
                                            ,"prod_name"        => urldecode($nameUrl)
                                            ,"prod_min_price"   => $min_order_price
                                            ,"prod_min_qty"     => $min_order_qty
                                            ,"prod_desc"        => $prod['prod_desc']
                                            ,"prod_code"        => $prod['prod_code']
                                            ,"prod_pic_thumb"   => $default_pic_row['pic_thumb']
                                            ,"product_colours_image"    => ""
                                            ,"prod_spec_cats"   => $product_spec_cats
                                            ,"prod_spec_off"    => $product_spec_off
                                            );
        }

当我尝试添加 £ 符号时,它显示不允许使用键字符。我希望当我添加特殊字符并传入 url 时,产品将通过特殊字符显示。

我尝试查看system/libraries/Input.php 文件中的文件并尝试更改function _clean_input_keys 中代码的一个小位,但它没有用。有人可以帮我弄清楚这件事吗?非常感谢任何帮助。

TIA

【问题讨论】:

  • 你的 CodeIgniter 版本是什么?
  • 嗯我不知道..也许 2+ 我只是在解决一些问题
  • 显示 print_r($prod_name_url)echo $nameUrl 的输出并用实际的错误消息注释哪一行抛出错误
  • 这是 print_r($prod_name_url) 50ml 标准夹式洗手液£50ml 标准夹式洗手液£ 和 $nameUrl = urlencode($prod_name_url);回声“
    ”;回声 $nameUrl;回声“
    ”;显示这个 50ml+Standard+Clip+Hand+Sanitisers%26pound%3B
  • 你好有人可以帮我吗?

标签: php codeigniter


【解决方案1】:

您必须对井号进行 url 编码。构建您的 url 字符串,然后将其传递给 php urlencode($url) 函数,该函数会将其转换为允许的字符:“%a3”代表“£”

要检索它,请使用urldecode($url)

【讨论】:

  • 啊,我明白了,在这个 urldecode($url) 中,井号会读取吗?并且页面将能够显示?
  • 所以 ummm 我是不是不用触摸 system/libraries/Input.php 文件中的文件?
  • 不,你只需要使用urlencode("testing-product-nutella£"),它就会为你创建一个安全的url字符串。您不能将未编码的 £ 放在需要转换为“%a3”的 url 中,这是该字符的 urlencoded 版本
  • 啊,好吧,所以我必须先进行 urlencode,然后在检索时保存在数据库中后使用 urldecode?是吗?
  • 是的,听起来很像。当您想让 url 可读时,请使用 urldecode()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-22
相关资源
最近更新 更多