Kenji
kenji****@club*****
2009年 5月 18日 (月) 13:05:53 JST
Kenji です。 On Sun, 17 May 2009 22:34:48 +0900 kaz <okui****@sanne*****> wrote: > こんばんは、kazです。 > ユーザ認証についてご教授お願いします。 > delete_file/index/ファイル名にアクセスしたらログイン画面になってログインしたらtrashにコピーしてrecording_fileのレコードを削除したいのですが、なぜかログイン画面に遷移する前にtrashにレコードをコピーしてしまってます。 > どこが悪いのか何回も見直してるんですがわからず、煮詰まってます。 > なにかヒントなど頂けないでしょうか? header("Location:".$this->config->item('base_url')."index.php/auth/auth/login"); の後に exit していないからです。 // Kenji > controllers/recording_list/delete_file.php > <?php > class Delete_file extends MY_Controller > { > function Delete_file() > { > parent::MY_Controller(); > } > > function index($file) > { > > //echo $file;exit; > $query = $this->db->query("SELECT * FROM recording_file where file='$file'"); > $row = $query->row(); > > $data = array('delete_date' => date('Y-m-d-H:i:s',time()), > 'date' => $row->date, > 'station' => $row->station, > 'station_code' => $row->station_code, > 'location' => $row->location, > 'file' => $row->file, > 'program' => $row->program, > 'title' => $row->title, > 'info' => $row->info, > 'tuner' => $row->tuner > ); > $this->db->insert('trash', $data); //trashにデータコピー > > // $this->db->delete('recording_file', array('file' => $file)); > // redirect('auth/auth/logout'); > } > > } > ?> > > libraries/MY_Controller.php > <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); > class MY_Controller extends Controller > { > function MY_Controller() > { > parent::Controller(); > $this->load->library('session'); > //login check > if($this->session->userdata('is_login') != TRUE) > { > > //redirect page check > if(!$this->session->userdata('next')) > { > $newdata = array( > 'next' => $this->uri->segment(2), > 'file' => $this->uri->segment(4) > ); > $this->session->set_userdata($newdata); > } > header("Location:".$this->config->item('base_url')."index.php/auth/auth/login"); > } > } > } > ?> > > controllers/auth/auth.php > <?php > class Auth extends Controller > { > var $user_table = 'users'; //管理者情報のDBテーブル名 > > function Auth() > { > parent::Controller(); > $this->load->library(array('session', 'validation')); > } > > function index() > { > $data['username'] = ""; > $data['password'] = ""; > $this->load->view('auth/login_form_view', $data); > } > > function login() > { > //after login > if($this->session->userdata('is_login') == TRUE) > { > $next = $this->session->userdata('next'); > $file = $this->session->userdata('file'); > //echo $next;echo $file;exit; > redirect($next.'/index/'.$file); > } > > //before login > $username = $this->input->post('username'); > $password = $this->input->post('password'); > > if($_SERVER['REQUEST_METHOD'] == 'POST') > { > $cancel = $this->input->post('cancel'); > } > > //validation rules > $rules['username'] = "trim|required"; > $rules['password'] = "trim|required"; > $this->validation->set_rules($rules); > > //validation check > $data['page_title'] = "login"; > $data['title'] = "ログイン"; > if ($this->validation->run() == TRUE) > { > //login check > if ($this->_db_check($username, $password)) > { > if (isset($cancel) and $cancel == "CANCEL") > { > redirect(''); > } else { > //login OK > $next = $this->session->userdata('next'); > $file = $this->session->userdata('file'); > $this->session->sess_destroy(); > $this->session->sess_create(); > $this->session->set_userdata(array('is_login' => TRUE)); > $this->session->set_userdata(array('username' => $username)); > redirect('recording_list/'.$next.'/index/'.$file); > } > //redirect($next); > } > else > { > if (isset($cancel) and $cancel == "CANCEL") > { > redirect(''); > } else { > //login NG > $data['username'] = ""; > $data['password'] = ""; > $this->load->view('auth/login_form_view', $data); > } > } > } else { > //validation error or first access > if (isset($cancel) and $cancel == "CANCEL") > { > redirect(''); > } else { > > > $data['username'] = $username; > $data['password'] = $password; > $this->load->view('auth/login_form_view', $data); > } > } > } > > function logout() > { > $this->session->sess_destroy(); > redirect(''); > } > > function _db_check($username = '', $password = '') > { > $this->db->where('username', $username); > $query = $this->db->get('users'); > if (0 < $query->num_rows()) > { > $row = $query->row_array(); > if(md5($password) == $row['password']) > { > return TRUE; > } > else > { > return FALSE; > } > } > else > { > return FALSE; > } > } > > > } > ?> > > _______________________________________________ > Codeigniter-users mailing list > Codei****@lists***** > http://lists.sourceforge.jp/mailman/listinfo/codeigniter-users