Welcome Guest, Not a member yet? Register   Sign In
Session data lost
#1

[eluser]alvaroeesti[/eluser]


Hi,

over a week stuck with the issue and not even showing it on a video did I get any clue.

Scenario:

I have a form in the frontpage to select data which retrieves rows of data in the next page inside. Results are displayed ok, but they need to be paginated. No way to get that. All examples of pagination are based on too easy scenarios, where they just directly fetch all of the rows from a table but there are no posted variables with data received from a form elsewhere on the web to be used to retrieve specifically filtered data (with WHERE clauses)

The posted values from the form are received by a controller, which validates them and does display the rows of data corresponding to those values in that table.

However, when I click on the pagelink, nothing is retrieved.

I tried then to do this:

Just put in a session array the posted values originally selected in the form. like country, state, region and item. However, those session values are also lost! wtf! they are session values, they are supposed to be globally available!

This is what I did:

Code:
public function validateData($offset = '')
{$this->form_validation->set_rules('object', 'object', 'trim|max_length[30]|xss_clean');
  $this->form_validation->set_rules('paises', 'paises', 'trim|max_length[30]|xss_clean');

.....

$object = $this->input->post('object');
$paises = $this->input->post('paises');

...

//Here is where I create the session array to store the posted values from the Form:

$newdata = array(
'object'  => $object,
'paises'  => $paises,
....

//And this effectively saves those values in a cookie session:

$this->session->set_userdata($newdata);

Well, I have that in the controller that receives the data from the form, AND I also put it in the view page that that controller loads in order to show the displayed data. Those session values are still kept this far, BUT, when I click on the pagelink to wishfully expect another chunk of data (from the Limit and Offset stuff), all goes blank, the array goes to 0 and all session data are gone.
#2

[eluser]benton.snyder[/eluser]
To answer the underlying question, nothing magically disappears in programming languages. We can't really help you troubleshoot the issue without seeing more of the code. Yes, we can see that you are setting the variables, but obviously something is happening afterwards. That is what we need to see to help.

I would certainly enable CI's debugging so that you can see all of the session variables from the client side. Are the variables even defined after the first page just with null/unexpected values? Or are they no longer even allocated?

Make sure that you are session_start()'ing on every page, that there are no session_destroy()'s or that the data isn't being redefined. Otherwise, post more code.
#3

[eluser]alvaroeesti[/eluser]
session_start() on every page? but doesn't CI take care of that? I thought that was when you use PHP native sessions?

I autoload the session so, that should be all. I have included all the code I have related to session mngmt.

as you can see above I do validation, then I accept the values posted from the form and then I create an array called newdata where I store the values in the session.

Aside from that I have read that CI sessions do not work with IE. If that is so, and it is according to many developers, then how do I implement PHP native sessions? Do I need to load any library?

#4

[eluser]benton.snyder[/eluser]
Because you are not showing the *ALL* of the relevant sections of code, I was only offering theoretical answers to your question. If you are autoloading the session library then the session data should be available throughout the entire application.

If you believe this to be a problem with IE, try it in another browser. Have you looked at the debugging information to see if any session variables are carrying over, just not the user defined variables? Again, we are happy to help, but our hands are tied if you can't/won't show us the code.
#5

[eluser]alvaroeesti[/eluser]

In this video I show the issue I have, and all the relevant code it is 3 minutes. If you have a solution for this issue, I have been stuck for a week so far

http://www.screencast.com/t/2zR3JL5ug


As per the debugging, I use firebug to watch what happens and what I am seeing in the ci_sessions is cookies that show the values of the returned queries from the DB, and that is not what I want to save in the session, (aside from the fact that there is room for 4kb only in a cookie) what I want to save in a session and try to put it available for the pagelink queries is the posted values at the webform, the one that is shown on the video
#6

[eluser]benton.snyder[/eluser]
Unfortunately this older computer and poor screen make it very hard to make out the actual code in that screencast. One thing I did notice was that you are not "autoloading" the session library. It looks like you are loading libraries in your controller's constructor?

I do feel for your struggle, but if you want fruitful help from this forum, you're going to need to paste the code. It just might be worth the 5 minutes it would take to format and remove any compromising code...
#7

[eluser]alvaroeesti[/eluser]
Thank you for your efforts.

The session idea I implemented it today while the video I created it a few days ago, so that is why it is not showing. I have no problem in showing the code. I am going to put each chunk of code, because to put repeating concepts does not help you, if I say, $firstname, $lastname etc you dont need to go through telephone number, street etc the key issue is how one function relates to other:


1. FRONT PAGE, PART OF THE FORM THAT IS LOADED BY CONTROLLER: home_C.php. Its view is called Home_view.php and its model, home_model.php

So here you see one select list, but think that there are 4 or 5 more. Notice that this is in a form which sends the data to another controller which will validate and will send the validated data to a model and finally will launch another view with the results that I want to paginate.

Code:
<?php echo form_open(base_url() . 'index.php/resultados_search_C/validateData'); ?>

<ul>

<li>
  <select name ="object" id = "object">
  <option value = "flat" selected "flat">Flat</option>
  <option value = "house">House</option>
  <option value = "houseshare">Houseshare</option>
  <option value = "commercial">Commercial</option>
  <option value = "land">Land</option>
  <option value = "cottage">Cottage</option>
  </select>
  <select name ="paises" id = "paises">
&lt;?php echo form_close(); ?&gt;

So whatever the user selects will be posted to this controller: resultados_search_C.php., specifically to its function validateData.php

Code:
function __construct()
{
  
  parent::__construct();
    
  $this->load->library('googlemaps');
  $this->load->model('resultados_search_M1');
  $this->load->library('pagination');
  $this->load->library('session');
  
}

function index ()
{
  ;  
    
}




private $object;
private $paises;
private $address;
private $transaction_type;
private $regiones;

// so more variables ... and now the validation

public function validateData($offset = '')
{
  
  
  $this->form_validation->set_rules('object', 'object', 'trim|max_length[30]|xss_clean');
  $this->form_validation->set_rules('paises', 'paises', 'trim|max_length[30]|xss_clean');
  $this->form_validation->set_rules('address', 'address', 'trim|max_length[100]|xss_clean');


// as you can imagine there are more validation lines for all of the posted variables


//  so now once that is validated, it is passed to variables which will be sent as parameters to the Model resultados_search_M.php


   $object = $this->input->post('object');
   $paises = $this->input->post('paises');
   $regiones = $this->input->post('regiones');
   $address = $this->input->post('address');
   $transaction_type = $this->input->post('transaction_type');



// before I actually send that to the Model, today I had the idea of storing that posted data in a session, like this


   $newdata = array(
     'object'  => $object,
     'paises'  => $paises,
     'regiones'=> $regiones,
     'address'=> $address,
     'transaction_type'=> $transaction_type,
                                         etc);

$this->session->set_userdata($newdata);


// so I send the stuff to the Model

$data = $this->resultados_search_M1->devolverResultadosMapa($object, $paises, $regiones,

// Notice in the line above that I dont save the returned data from the Model into an array as of yet
// this is because, in order to launch the googlemaps I need it so.

// Further underneath I do write an index to make it an array (the index is datos)

// in there I also send the Limit and the Offset


// This is for the pagination

$data['datos'] = $data;
  
  
  
   # NOW WITH PAGINATION
  
   $config['base_url'] = site_url('resultados_search_C/validateData');
   $config['rows'] = $this->session->all_userdata();
   $config['total_rows'] = $total_filas;
   $config['per_page'] = $limit;
   $config['uri_segment'] = 3;
   $this->pagination->initialize($config);
   $data['pagelinks'] = $this->pagination->create_links();
  
   $this->load->view('resultados_search_V1', $data, $data_mapa );
  
// I am now in the view where the displayed rows are shown and it is
// here where I want to paginate

&lt;?php foreach($datos as $encontrados): ?&gt;
&lt;?php


// That above was to display the rows

// and here comes the hell. The pagelinks, upon whose clicking all is lost

</div> &lt;?php echo $pagelinks;?&gt;
I have no problem in posting all the code, but it would take like 5 pages. However, all the key logic is included.



#8

[eluser]benton.snyder[/eluser]
Please add the following line to the resultados_search_C controller's constructor:

Code:
$this->output->enable_profiler(TRUE);

When you click on a $pagelink, what does the $_SESSION section include at the bottom of the page? Do you see any $_SESSION variables defined? Do they have values? Do you see your user defined variables? etc.
#9

[eluser]alvaroeesti[/eluser]
I appreciate a lot your help. If you want I can send you just the full pack of the site zipped, together with the database. I am trying to develop a real estate portal, and I was doing well until I got stuck here. Data in the DB are just to fill the blanks, nothing confidential there.

I think it is much easier for you if you can see it running than trying to see in the dark of distance.

I got a large display of stuff but I am not quite sure as to how to interpret it.

==============

When I click on the page links, the controller page loads but because it has no values in the variables, the query is sent to the model empty.

Also session variables empty.

When I start from the frontpage, I can see the posted values and that they are embedded in the sql query, but that does not happen when I click the pagelinks. That is, the pagelinks contain no information to send in order to get the next chunk of data for a paginated display.

#10

[eluser]benton.snyder[/eluser]
If it's a mysql backend, pm me the zip and I'll take a look.




Theme © iAndrew 2016 - Forum software by © MyBB