Welcome Guest, Not a member yet? Register   Sign In
Retrieve different session value instead of original one
#1

I'm using Codeigniter 3 framework and encounter a problem.
In my app, there is 2 controller:
Main and User.
In Main controller, there are two methods, method1 (with no parameter) and method2 (with one parameter), which both load own view, but there is an identical form in their view that will be submitted to User controller method. In both method1 and method2, I generate a random number and store in $data['random'], also in a session variable (for future checking):
$data['random'] = generate_random();
$this->session->set_userdata('random', $data['random']);
$data['random'] in both method is set in form input and then submitted.
The problem is: when I retrieve data (in User controller) which is submitted from method1, and compare with session value, they are equal. BUT this scenario for method2 is different. the submitted value is not equal to session value!!!
The only difference between methods is: method2 accept parameters and method1, no.
NOTE: when I assign a fixed number (instead of generate random) to $data['random'], the result of both methods are equal.


The Main controller methods:

Code:
public function method1(){
//other data setting and...

$data['random'] = generate_random();
$this->session->set_userdata('random', $data['random']);

$this->load->view('view_folder/first', $data);
}

public function method2($param){
//other data setting and...

$data['random'] = generate_random();
$this->session->set_userdata('random', $data['random']);

$this->load->view('view_folder/second', $data);
}


The User controller method:

Code:
public function check(){
echo $this->input->post() . '<br>';
echo $this->session->userdata('random');
exit();
//other...
}


In view files, an identical form is part of view code. As I said, $data['random'] will be set as input value in form and this will be submitted. Another thing, in first view file, there some items which link to method2:

Code:
<!-- other -->
<a href="<?php echo base_url();?>main/method2/3">some item</a>
<a href="<?php echo base_url();?>main/method2/some_var">some item</a>
<!-- other -->


I check code carefully, test different cases, I think this problem related to passed argument to method2. I mean, the passed parameter create problem. But I have no idea and logical reason!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB