codeigniter搭配php 5.3中兩個值得注意的問題

來源:互聯網
上載者:User
codegniter 1.7跟PHP5。3配合時,有些地方要改下的,主要是php 5.3有不少跟php 5.2不同的地方了,要特別留意下,

1 PHP:Deprecated: Function set_magic_quotes_runtime() is deprecated 錯誤:

  PHP5.3和PHP6.0之後移除了set_magic_quotes_runtime()函數。

set_magic_quotes_runtime(0)函數作用解釋

在php.ini的設定檔中,有個布爾值的設定,就是magic_quotes_runtime,當它開啟時,php的大部分函數自動的給從外部引入的(包括資料庫或者檔案)資料中的溢出字元加上反斜線。

當然如果重複給溢出字元加反斜線,那麼字串中就會有多個反斜線,所以這時就要用set_magic_quotes_runtime()與 get_magic_quotes_runtime()設定和檢測php.ini檔案中magic_quotes_runtime狀態。

為了使自己的程式不管伺服器是什麼設定都能正常執行。可以在程式開始用get_magic_quotes_runtime檢測設定狀態秋決定是否要手工處理,或者在開始(或不需要自動轉義的時候)用set_magic_quotes_runtime(0)關掉。

magic_quotes_gpc設定是否自動為GPC(get,post,cookie)傳來的資料中的'"\加上反斜線。可以用 get_magic_quotes_gpc()檢測系統設定。如果沒有開啟這項設定,可以使用addslashes()函數添加,它的功能就是給資料庫查詢語句等的需要在某些字元前加上了反斜線。這些字元是單引號(')、雙引號(")、反斜線(\)與 NUL(NULL 字元)。

解決辦法:

//@set_magic_quotes_runtime(0);

ini_set("magic_quotes_runtime",0);

就是用ini_set()辦法替代原有的set_magic_quotes_runtime文法。

2  “The URI you submitted has disallowed characters.” error CodeIgniter

1) in codeigiter system/libraries open  URI.php  line 189 you’ll find

if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", rawurlencode($str)))

Change that to:

if ( ! preg_match("|^[".($this->config->item('permitted_uri_chars'))."]+$|i", rawurlencode($str)))

Note we removed the preg_quote().  Now in your system/application/config/config.php file  look for line 126 (unless you’ve added a lot to you config will be around there somewhere)

Change the line

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';

to:

$config['permitted_uri_chars'] = 'a-z 0-9~%\.\:_\-';

3 php5.3開始後,廢除了php中的”=&”符號,所以要想複製,直接用=引用即可。

比如:

  freakauth_light = & new MyFAL();

改為 $obj->freakauth_light =  new MyFAL();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.