2014-12-13 48 views
-1

我在這裏遇到了嚴重的網站問題。我不是一個PHP開發人員,但我知道基礎知識。所以如果我在這裏犯了什麼錯誤,請儘量原諒我。所選控制器和選定功能名稱的SSL [CodeIgniter]

我的網站是使用CodeIgnitor構建的,而且我對某些被控制器或控制器名稱或函數名稱控制的選定頁面擁有SSL。

一樣 - 這些

$ssl_controllers = array('controller1','controller2','controller3'); 

URL結構,我有SSL是這樣的 - https://mysite.com/controller1

現在,我有每個控制器內多個功能。這樣的 - 「控制器1」裏面,我有「function_1()」

所以網址將是 - https://mysite/controller1/function_1

現在我不需要SSL的「funtion_1」,這是「控制器1」

裏面寫

如果我需要刪除「function_1」的SSL,我需要從陣列中刪除整個「controller1」。但是我不需要這個,因爲還有其他需要SSL的功能。

那麼我如何刪除「function_1」的SSL?

有沒有辦法從數組中刪除函數名?

這樣的 - $ ssl_controllers =

$ssl_controllers = array('controller1'==>'function_1','controller2','controller3'); 

請幫助我!

謝謝!


由於我沒有使用htaccess重定向,您的方法不適用於我的情況。如果我使用htaccess,它會給我無限循環,無法完成!這是因爲我使用CodeIgnitor庫重定向和特定頁面SSL


這裏是PHP代碼 -

class CI_ssl{ 

    function check_ssl() 
    { 
     $CI =& get_instance(); 
     $class = $CI->router->fetch_class(); 
     $ssl_controllers = array('controller1','controller2','controller3'); 

     if(in_array($class,$ssl_controllers)) 
     {      
      $CI =& get_instance(); 
      $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);   

      if ($_SERVER['SERVER_PORT'] != 443) 
       redirect($CI->uri->uri_string()); 
     } 
     else 
     { 
      $CI =& get_instance(); 
      $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); 
      if ($_SERVER['SERVER_PORT'] == 443) 
       redirect($CI->uri->uri_string()); 
     } 
    } 

這讓我對SSL特定頁面和重定向等只有HTTP://

回答

-1

經過今天的研究後,我終於解決了我的問題。這裏是演示 -

$CI =& get_instance(); 
$class = $CI->router->fetch_class(); 
$ssl_controllers = array('controller1','controller2','controller3'); 

在這段代碼中,我已經叫特異功能這樣 -

$CI =& get_instance(); 
$class = $CI->router->fetch_class(); 
$ssl_controllers = array('controller1','controller2','controller3'); 
$my_function = $CI->router->fetch_method(); // fetch method is used for getting the specific function name 
$ssl_functions = array('function_1'); // specific function name in array 

然後,我只是說elseif的語句來我的病情 -

if(in_array($my_function,$ssl_functions)) 
     { 
      $CI =& get_instance(); 
      $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); 
      if ($_SERVER['SERVER_PORT'] == 443) 
       redirect($CI->uri->uri_string()); 
     } 
     elseif(in_array($class,$ssl_controllers)) 
     {      
      $CI =& get_instance(); 
      $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);   
      //echo $CI->config->config['base_url']."=>".$CI->uri->uri_string()."=>".$_SERVER['SERVER_PORT'];exit;   
      if ($_SERVER['SERVER_PORT'] != 443) 
       redirect($CI->uri->uri_string()); 
     } 
     else 
     { 
      $CI =& get_instance(); 
      $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); 
      if ($_SERVER['SERVER_PORT'] == 443) 
       redirect($CI->uri->uri_string()); 
     } 
    } 

因此,我的新網址沒有SSL!像這樣 -

http://mysite/controller1/function_1 
0

在你的.htaccess使用重寫規則:

RewriteCond %{SERVER_PORT} !80 
RewriteCond %{REQUEST_URI} controller1/function_1 
RewriteRule ^(.*)$ http://www.yourdomain.com/controller1/function_1 [R=301,L] 

注意:您BASE_URL米在配置文件中將ust設置爲「/」。

+0

您好先生,因爲我沒有使用htaccess重定向,您的方法不適用於我的情況。如果我使用htaccess,它會給我無限循環,無法完成! 這是因爲我使用CodeIgnitor庫進行重定向和特定頁面SSL。 – Amit 2014-12-13 12:45:01

相關問題