我正在使用XAMPP处理CodeIgniter。当我在子域上传文件时,它会给我一个错误,但它在我的本地机器上工作。
这是我的控制器
if ($this->session->userdata('admin_email') && $this->session->userdata('admin_id')) {
$data['title'] = $this->session->userdata('admin_name');
$this->load->view('admin/header',$data);
$this->load->view('admin/topbar');
$this->load->view('admin/sidebar');
//$this->load->view('admin/home');
$this->load->view('admin/footer');
}
else
{
$this->session->set_flashdata('adminlogin','please login first..');
redirect('admin/login');
}
这是我的错误:
遇到PHP错误
严重性:警告
消息:无法修改标头信息 - 已发送的标头 (输出始于 /home/shakzeec/public_html/demo/application/controllers/admin.php:2)
文件名:libraries / Session.php
行号:688遇到PHP错误
严重性:警告
消息:无法修改标头信息 - 已发送的标头 (输出始于 /home/shakzeec/public_html/demo/application/controllers/admin.php:2)
文件名:libraries / Session.php
行号:688遇到PHP错误
严重性:警告
消息:无法修改标头信息 - 已发送的标头 (输出始于 /home/shakzeec/public_html/demo/application/controllers/admin.php:2)
文件名:helpers / url_helper.php
行号:542
答案 0 :(得分:0)
一旦输出已经启动,PHP不允许您修改标头。重定向需要更改标题。如果您想重定向,请只进行重定向,不做任何其他操作。
if (!$this->session->userdata('admin_email') && !$this->session->userdata('admin_id')) {
$this->session->set_flashdata('adminlogin','please login first..');
redirect('admin/login');
}
else{
$data['title'] = $this->session->userdata('admin_name');
$this->load->view('admin/header',$data);
$this->load->view('admin/topbar');
$this->load->view('admin/sidebar');
//$this->load->view('admin/home');
$this->load->view('admin/footer');
}
另外,在修改标题之前,请确保控制器中没有其他内容可以发送输出。
答案 1 :(得分:0)
这是controllers / employer.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Employers extends CI_Controller {
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Manila");
$this->load->model('_user');
}
public function index()
{
$data['userlist'] = $this->_user->get_user_list();
$this->load->view('employers/index', $data);
$this->template->render();
}
public function registration()
{
$data['userToken'] =$this->scriptor->userToken();
$data['userlist'] = $this->_user->get_user_list();
if(!isset($_REQUEST['msg'])){ $_REQUEST['msg'] = ''; }
$this->load->view('employers/registration', $data);
$this->template->render();
}
public function newregister()
{
$dr = strlen($_SERVER['PHP_SELF']) - 9;
$path = $_SERVER["DOCUMENT_ROOT"] .substr($_SERVER['PHP_SELF'], 0, $dr) .'image/source/employer/' . strtolower($this->input->post('Username'));
if(!is_dir($path)){
//Make Directory
if (!mkdir($path, 0777, true)) {
die('Failed to create folders...');
}
}
$config['upload_path'] = $path;
$config['file_name'] = url_title(strtolower($this->input->post('Username'))) . $this->upload->data('file_ext');
$config['allowed_types'] = 'gif|jpg|png|';
$config['max_size'] = '';
$config['max_width'] = '';
$config['max_height'] = '';
$this->upload->initialize($config);
$err = 'failed_reg';
$ok = true;
if(strlen($this->input->post('Username')) == 0){
$ok = false;
$err = 'err_username';
}
if(strlen($this->input->post('Lastname')) == 0 && $ok){
$ok = false;
$err = 'err_lastname';
}
if(strlen($this->input->post('Firstname')) == 0 && $ok){
$ok = false;
$err = 'err_firstname';
}
if(strlen($this->input->post('Email')) == 0 && $ok){
$ok = false;
$err = 'err_email';
}
if(strlen($this->input->post('Cellphone')) == 0 && $ok){
$ok = false;
$err = 'err_cellphone';
}
if(strlen($this->input->post('Telephone')) == 0 && $ok){
$ok = false;
$err = 'err_telephone';
}
if(strlen($this->input->post('Address')) == 0 && $ok){
$ok = false;
$err = 'err_address';
}
if(strlen($this->input->post('City')) == 0 && $ok){
$ok = false;
$err = 'err_city';
}
if(!$this->upload->do_upload('EmpPic') && $ok){
$ok = false;
if(is_dir($path)){
array_map('unlink', glob($path."/*"));
rmdir($path);
}
$err = 'err_image';
}
if($_FILES['EmpGovID']['size'] > 0){
if(!$this->upload->do_upload('EmpGovID') && $ok){
$ok = false;
if(is_dir($path)){
array_map('unlink', glob($path."/*"));
rmdir($path);
}
$err = 'err_image2';
}
}
if($ok){
$i = array(
'Firstname' => $this->scriptor->_enc($this->input->post('Firstname'))
, 'Middlename' => $this->scriptor->_enc($this->input->post('Middlename'))
, 'Lastname' => $this->scriptor->_enc($this->input->post('Lastname'))
, 'Telephone' => $this->scriptor->_enc($this->input->post('Telephone'))
, 'Cellphone' => $this->scriptor->_enc($this->input->post('Cellphone'))
, 'Email' => $this->scriptor->_enc($this->input->post('Email'))
, 'Address' => $this->scriptor->_enc($this->input->post('Address'))
, 'City' => $this->scriptor->_enc($this->input->post('City'))
, 'EPicture' => base_url('image/employer') . '/'.$config['file_name']
, 'Username' => $this->scriptor->_enc($this->input->post('Username'))
, 'Password' => $this->scriptor->_enc($this->input->post('Password'))
, 'Token' => $this->scriptor->userToken()
, 'Level' => 'user'
, 'Yatype' => $this->scriptor->_enc($this->input->post('Yatype'))
, 'GovID' => base_url('image/employer') . '/'.$config['file_name']
, 'q1' => $this->scriptor->_enc($this->input->post('q1'))
, 'q2' => $this->scriptor->_enc($this->input->post('q2'))
, 'q3' => $this->scriptor->_enc($this->input->post('q3'))
, 'aq1' => $this->scriptor->_enc($this->input->post('aq1'))
, 'aq2' => $this->scriptor->_enc($this->input->post('aq2'))
, 'salary' => $this->scriptor->_enc($this->input->post('salary'))
, 'registeredDate' => date('Y-m-d h:i:s')
, 'Message' => $this->scriptor->_enc($this->input->post('Message'))
);
$this->_user->add($i);
redirect('employers/registration?msg=success_reg');
} else {
redirect('employers/registration?msg='. $err);
}
/******************************************************************/
}//End Class
}