redirect()转到链接然后重定向到codeigniter中的主网站?

时间:2018-05-05 08:51:26

标签: codeigniter

我有使用codeigniter编写的代码,其redirect()如下所示:

   if(isset($_POST['Search'])) 
   {
    $link = SITE_URL."generate_prn/";
    if($this->input->post('cin')){  
    $link .= "cin/".$this->input->post('cin')."/";  
    }
   $this->session->set_userdata('link',$link);
   redirect($link,'refresh');
   $data['list']=$_POST;
  }

$ link的值为“http://website.com/accounts/registration/generate_prn/cin/17ASA10000/”。在上面的代码中,它会重定向到上面给出的$ link值,然后再次重定向到网站“http://website.com/”。我不希望它重定向到网站,但它应该保持在上面给出的链接值。任何人都可以帮助我,以及如何防止它进入主网站?

完整代码(generate_prn.php)是

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Generate_prn extends CI_Controller {

    public function __construct() {
        parent::__construct();
        if (!$this->session->userdata('user_id')) {
            redirect('login/', 'refresh');
        }
    }

    public function index() {
        if (isset($_POST['Search'])) {
            $link = SITE_URL . "generate_prn/";
            if ($this->input->post('cin')) {
                $link .= "cin/" . $this->input->post('cin') . "/";
            }
            $this->session->set_userdata('link', $link);
            redirect($link, 'refresh');
            $data['list'] = $_POST;
        } else {
            $data['info'] = '';
            $uri = $this->uri->uri_to_assoc(4);
            $aim = $uri['aim'];
            if ($uri['cin'] != '') {
                $cin = $uri['cin'];

                if (isset($_POST['Submit'])) {
                    $receipt_date = $this->input->post('receipt_date');
                    $timestamp = strtotime($receipt_date);
                    $date = date('Y-m-d', $timestamp);
                    $action = $data['stud_competition_data']['status'];
                    /* echo $action;exit; */
                    switch ($action):
                        case 'NOT_REG' :

                            $validate_data = array(
                                'receipt_number' => $this->input->post('receipt_number'),
                                'receipt_date' => $this->input->post('receipt_date'),
                                'branch_name' => $this->input->post('branch_name')
                            );

                            $this->validation->set_rules('branch_name', 'branch_name', 'required');
                            if ($this->validation->run() === FALSE) {
                                //var_dump($this->validation->show_errors());
                                $this->notifications->notify('Please make all entries', 'error');
                            } else {
                                $regstration_data = array(
                                    'competition_schedule_id' => $competition_schedule_id,
                                    'student_id' => $student_id,
                                    'receipt_number' => $receipt_number,
                                    'branch_name' => $branch_name,
                                    'receipt_date' => $date,
                                    'frcode' => $frcode,
                                    'period_name' => $period_name,
                                    'levelcode' => $levelcode,
                                    'period' => $period_id
                                ); else {
                                    echo $this->notifications->notify('Registration failed', 'error');
                                }
                                redirect('accounts/generate_prn', 'refresh');
                            }
                            break;
                        case 'ALREADY_REG':
                            $validate_data = array(
                                'receipt_number' => $this->input->post('receipt_number'),
                                'receipt_date' => $this->input->post('receipt_date'),
                                'branch_name' => $this->input->post('branch_name')
                            );
                            $this->validation->set_data($validate_data);
                            $this->validation->set_rules('receipt_number', 'receipt_number', 'required');
                            $this->validation->set_rules('receipt_date', 'receipt_date', 'required');
                            $this->validation->set_rules('branch_name', 'branch_name', 'required');
                            if ($this->validation->run() === FALSE) {
                                //var_dump($this->validation->show_errors());
                                $this->notifications->notify('Please make all entries', 'error');
                            } else {



                                /* $timestamp      = strtotime($reciept_date);
                                  $date           = date('Y-m-d', $timestamp); */
                                $prn_no = $data['stud_competition_data']['upcoming_schedule_deatils'][0]['permenent_registration_number'];
                                if (empty($prn_no)) {
                                    $regstration_data = array(
                                        'competition_registration_id' => $competition_registration_id,
                                        'competition_schedule_id' => $competition_schedule_id,
                                        'student_id' => $student_id,
                                        'receipt_number' => $receipt_number,
                                        'branch_name' => $branch_name,
                                        'receipt_date' => $date,
                                        'frcode' => $frcode,
                                        'period_name' => $period_name,
                                        'period' => $period_id,
                                        'levelcode' => $levelcode,
                                    );
                                    $comp_reg_status = $this->accountsmodel->generate_prn($regstration_data);
                                } else {
                                    //echo "prn no empty";exit;

                                    $comp_reg_status = $this->accountsmodel->update_reg_details($regstration_data);
                                }
                                /* echo "<pre>";print_r($regstration_data);exit;     */
                                if ($comp_reg_status) {
                                    echo $this->notifications->notify('REGISTRATION DETAILS UPDETED', 'success');
                                } else {
                                    echo $this->notifications->notify('Registration failed', 'error');
                                }
                                redirect('accounts/generate_prn', 'refresh');
                            }
                            break;
                    endswitch;
                }
                //redirect('accounts/registration/generate_prn', 'refresh');  
            } /* end of if of uri['cin']!='' */ else {
                $data['info'] = "empty";
            } /* END OF ELSE if of uri['cin']!='' */
        }
        $this->load->view("prn_generation.php", $data);
    }

}

?>

我有另一个页面,其中包含一个输入框和一个名为“搜索”的提交按钮。在输入框中输入值并在输入框中提交值后,它将转到generate_prn.php文件。

0 个答案:

没有答案