我在codeigniter的应用程序文件夹外部创建了一些文件。以下是我的文件夹和文件的结构
sys_config.php 是默认文件,如果满足条件,它将重定向到 b0a.php 或应用程序文件夹下的admin / login
sys_config.php代码
$sql ="SELECT host FROM tray WHERE host = '$host'";
$ret = mysqli_query($mysqli,$sql);
$row = mysqli_fetch_array($ret);
if ($row['host'] != '' && $row['host'] == $host) {
redirect("index", true);
} else {
//echo "<p>Nothing matched your query.</p>";
redirect("b02.php", true);
}
在控制器下的install.php中,我有这个
<?php
Class Install extends CI_Controller {
function __construct()
{
parent::__construct();
//load in some helpers
$this->load->helper(array('form', 'file', 'url','language'));
if($this->session->userdata('lang')!="")
{
$this->lang->load('admin',$this->session->userdata('lang'));
}else{
$this->lang->load('admin', 'english');
}
//if this system is already installed redirect to the homepage
if(file_exists(FCPATH.'application/config/setup.php'))
{
//redirect('admin/login');
redirect('sys_config');
}
$this->load->library('form_validation');
$this->load->library('session');
}
function index()
{
//build our checks
$data = array();
//Destroy All Session
$this->session->sess_destroy();
//check for writable folders
$data['is_writeable']['root'] = is_writeable(FCPATH);
$data['is_writeable']['config'] = is_writeable(FCPATH.'application/config/');
$data['is_writeable']['uploads'] = is_writeable(FCPATH.'uploads/');
$this->form_validation->set_rules('hostname', 'Hostname', 'required');
$this->form_validation->set_rules('database', 'Database Name', 'required');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'trim');
$this->form_validation->set_rules('prefix', 'Database Prefix', 'trim');
$this->form_validation->set_rules('ssl_support');
$this->form_validation->set_rules('mod_rewrite');
if ($this->form_validation->run() == FALSE)
{
$data['errors'] = validation_errors();
$this->load->view('install', $data);
}
else
{
// Unset any existing DB information
unset($this->db);
//generate a dsn string
$dsn = 'mysqli://'.$this->input->post('username').':'.$this->input->post('password').'@'.$this->input->post('hostname').'/'.$this->input->post('database');
//connect!
$this->load->database($dsn);
if (is_resource($this->db->conn_id) OR is_object($this->db->conn_id))
{
//setup the database config file
$settings = array();
$settings['hostname'] = $this->input->post('hostname');
$settings['username'] = $this->input->post('username');
$settings['password'] = $this->input->post('password');
$settings['database'] = $this->input->post('database');
$settings['prefix'] = $this->input->post('prefix');
$file_contents = $this->load->view('templates/database', $settings, true);
write_file(FCPATH.'application/config/database.php', $file_contents);
$setup_file = "//This Is Setup File";
write_file(FCPATH.'application/config/setup.php',$setup_file);
//setup the CodeIgniter default config file
$config_index = array('index'=>'index.php');
if($this->input->post('mod_rewrite'))
{
$config_index = array('index'=>'');
}
$file_contents = $this->load->view('templates/config', $config_index, true);
write_file(FCPATH.'application/config/config.php', $file_contents);
//setup the .htaccess file
if($this->input->post('mod_rewrite'))
{
$subfolder = trim(str_replace($_SERVER['DOCUMENT_ROOT'], '', FCPATH), '/').'/';
$file_contents = $this->load->view('templates/htaccess', array('subfolder'=>$subfolder), true);
write_file(FCPATH.'.htaccess', $file_contents);
}
$this->load->library('migration');
if ( ! $this->migration->current())
{
show_error($this->migration->error_string());
}
//redirect to the admin login
redirect('register');
}
else
{
$data['errors'] = '<p>A connection to the database could not be established.</p>';
$this->load->view('install', $data);
}
}
}
}
我使用以下命令重定向到应用程序文件夹外部的sys_config:
//if this system is already installed redirect to the homepage
if(file_exists(FCPATH.'application/config/setup.php'))
{
//redirect('admin/login');
redirect('sys_config');
}
一切正常。但是现在我试图重定向回admin / login,这给了我:
此页面无法正常运行localhost已多次重定向您。尝试 清除您的Cookie。 ERR_TOO_MANY_REDIRECTS
index.php
<?php
define('ENVIRONMENT', 'development');
/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*/
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*/
$system_path = 'system';
/*
*---------------------------------------------------------------
* APPLICATION FOLDER NAME
*---------------------------------------------------------------
*/
$application_folder = 'application';
// Set the current directory correctly for CLI requests
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}
if (realpath($system_path) !== FALSE)
{
$system_path = realpath($system_path).'/';
}
// ensure there's a trailing slash
$system_path = rtrim($system_path, '/').'/';
// Is the system path correct?
if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// The PHP file extension
// this global constant is deprecated.
define('EXT', '.php');
// Path to the system folder
define('BASEPATH', str_replace("\\", "/", $system_path));
// Path to the front controller (this file)
define('FCPATH', str_replace(SELF, '', __FILE__));
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
// The path to the "application" folder
if (is_dir($application_folder))
{
define('APPPATH', $application_folder.'/');
}
else
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
/* Location: ./index.php */
请,我如何从 sys_config.php 重定向到管理员/登录名?
答案 0 :(得分:1)
您应该从重定向检查中排除指向admin/login
的URL。因为这里发生的是它被重定向到admin/login
,我相信它可以进行登录检查,如果没有登录则可以使用重定向方法在其中不满足,因此将其重定向到引荐来源网址,依此类推。
在您检查中添加时,如果uri段字符串等于admin/login
,则不要重定向。