php - 如何从codeigniter中应用程序文件夹之外的另一个页面重定向到管理/登录页面
问题描述
我在 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
索引.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重定向到 admin/login?
解决方案
您应该admin/login
从重定向检查中排除 url .. 因为这里发生的是它被重定向到admin/login
我相信它有一个登录检查然后重定向方法如果未登录则不满足因此它被重定向到推荐人和很快 ..
在你检查添加如果 uri 段字符串等于admin/login
然后不要重定向。
推荐阅读
- ios - 如何在发布版本中获取 iOS 堆栈跟踪?
- google-cloud-speech - 'config' 中的未知名称 \"model\":找不到字段
- jpos - jpos客户端中的连接超时
- python - 如何将 Python 版本升级到 3.7?
- vb.net - 更好的性能 Linq To SQL 查询
- android - 我的 sql 删除命令使我的 db.insert 导致崩溃
- python - 如果在单元测试中跳过python中的代码
- laravel - 在中间件之间传递数据
- javascript - 从 Google Doc 到 Google Spreadsheet 复选框的交互式更改
- java - 在 Spring 安全中并发会话的情况下使第一个登录会话无效