停止直接访问url codeigniter

时间:2014-11-02 04:55:00

标签: php codeigniter

如果用户手动在URL中输入id,我希望他们被拒绝访问,就像控制器和模型顶部的codeigniter php一样。

我已经尝试过,但目前还没有编辑。我怎样才能让它发挥作用。

但是想点击编辑按钮时仍然可以访问。

继续说Parse error: syntax error, unexpected '{' in C:\Xampp\htdocs\codeigniter\project\application\modules\admin\controllers\website\website.php on line 43

public function edit() {
    if (!defined('base_url')) exit ('No direct script access allowed') {

     // If is ok.

        if ($this->input->server('REQUEST_METHOD') == 'POST') { 
            $website_id = $this->uri->segment(4);

            $config_name = $this->input->post('config_name');
            $config_url = $this->input->post('config_url');
            $config_ssl = $this->input->post('config_ssl');
            $this->model_website->editWebsite($config_name, $config_url, $config_ssl, $website_id);

            $this->model_website_setting->editSetting('config', $this->input->post(), $website_id);
            redirect('admin/website');

        }

        $this->getForm();

    } else {

        return false;
    }


 } 

1 个答案:

答案 0 :(得分:0)

这里有错误

if (!defined('base_url')) exit ('No direct script access allowed') {

此行if条件在exit ('No direct script access allowed')之后终止。然后else没有任何if

我认为你问的是下面的

public function edit() {
    if(defined('base_url')){
        if ($this->input->server('REQUEST_METHOD') == 'POST'){
            $website_id = $this->uri->segment(4);
            $config_name = $this->input->post('config_name');
            $config_url = $this->input->post('config_url');
            $config_ssl = $this->input->post('config_ssl');
            $this->model_website->editWebsite($config_name, $config_url, $config_ssl, $website_id);           
            $this->model_website_setting->editSetting('config', $this->input->post(), $website_id);
            redirect('admin/website');
        }
        $this->getForm();

    }else{
        exit ('No direct script access allowed');
        return false;
    }
}