Welcome Guest, Not a member yet? Register   Sign In
Help: Having set_userdata issues
#11

[eluser]bretticus[/eluser]
[quote author="fserrano" date="1253666523"]I should add that I can successfully add session user data upon login in my login.php controller. It is only after I am logged in that in the project.php controller I cannot set this new userdata.[/quote]

It's being set (to "js".) Are you sure you are grabbing the right segment?

EDIT: Maybe you didn't read my post before writing this. Anyway, all still applies.
#12

[eluser]fserrano[/eluser]
I am working locally. But here's the code.

project.php where I am having issues
Code:
<?php

class Project extends Controller {

    function Project()
    {
        parent::Controller();
        MY_getsubmenu();
        $this->load->helper(array('text','date'));
    }
    
    function index()
    {
        $this->load->view('project_view');
    }
    

    function view()
    {
        //Set default project to always remember the last project user was navigating
        if($this->uri->segment(3)!=NULL){
            $this->session->set_userdata('currentprojectid',$this->uri->segment(3));
            //Update user default project
            $this->db->where('id',$this->session->userdata('userid'));
            $this->db->update('users',array('defaultproject'=>$this->uri->segment(3)));
        } else {
            //Select default project from database
            //redirect('projects/$projectid/');
        }
        //Export data
        $data=array();
        $data['maincontent']="
             <h1>Title</h1>
             <fieldset>
                <legend>Log</legend>
                 <ul>
                 <li></li>
                 </ul>
                 <p>More...</p>
             </fieldset>
             <fieldset>
                <legend>Gallery</legend>
                 <ul>
                 <li></li>
                 </ul>
                 <p>More...</p>
             </fieldset>";
    
        //Get memos
        $data['activity']="<div id='memoslist'><fieldset><legend>Recent memos</legend><ul class='rollover'>";
        $this->db->order_by('date','desc');
        $this->db->limit(5);
        //If project is defined get memos in project only else get all memos in all projects
        if($this->uri->segment(4)){
            //$query=$this->db->get_where("memos",array('projectid'=>$this->session->userdata('currentprojectid')));
            $query=$this->db->get_where("memos",array('projectid'=>1));
        } else {
            $query=$this->db->get("memos");
        }
        foreach($query->result() as $row){
            //Project vars
            $submitterquery = $this->db->get_where('users',array('id'=>$row->userid));
            $submitternick = $submitterquery->row()->nickname;
            $datestring = "%M %d, %Y %h:%i %a";
            //$entrydate = mdate($datestring,strtotime($row->date));
            $entrydate = timespan(strtotime($row->date),time());
            $linkvalue=word_limiter(strip_tags($row->body),14)."<span><strong>$submitternick</strong> $entrydate ago</span>";
            $data['activity'].="<li><span class='icon'>".img('images/icon-memo.gif')."</span><span class='text'>".anchor("memo/view/".$row->id,$linkvalue)."</span><div class='clearleft'></div></li>";
        }
        //If project is defined get memos in project only
        $data['activity'].="</ul><p>More...</p></fieldset></div>";
        $data['activity'].=anchor('memo/form/'.$this->uri->segment(3),'Add one');
        $this->load->view('project_view',$data);
    }
}
#13

[eluser]fserrano[/eluser]
login.php where I can successfully set session userdata
Code:
&lt;?php
class Login extends Controller {

    function Login()
    {
        parent::Controller();
        getsubmenu();        
    }

    function index()
    {
        redirect('home');
    }

    function process()
    {
        $username = $this->input->post('username');    
        $password  = $this->input->post('password');
        //Validate values are not empty
        $this->form_validation->set_rules('username', 'Email', 'required|valid_email|trim|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'required');
        if ($this->form_validation->run() == FALSE)    {
            $this->load->view('home_view');
        } else {
            //Sanitize data
            //Check if loginname actually exists
            $this->db->where('email',$username);
            $query = $this->db->get('users');
            $checkusername = $query->row()->email;
            $checkpassword = $query->row()->password;
            $userid = $query->row()->id;
            if(!$checkusername){
                $this->session->set_flashdata('message', 'That email is not registered, try again.');
                redirect('login/process');
            } else {
                //Account exists so lets see if user and password are correct
                if ($username == $checkusername AND $password == $checkpassword) {
                    //Get user information to store in session: userid,companiesid,projectsids
                    $usercompanies=array();
                    $companies = $this->db->get_where('accounts_access',array('userid'=>$userid));
                    foreach($companies->result() as $row){
                        array_push($usercompanies,$row->accountid);
                    }
                    $userprojects=array();
                    $projects = $this->db->get_where('projects_access',array('userid'=>$userid));
                    foreach($projects->result() as $row){
                        array_push($userprojects,$row->projectid);
                    }
                    $data = array(
                           'username'  => $username,
                           'userid'  => $userid,
                           'usercompanies'  => $usercompanies,
                           'userprojects'  => $userprojects,
                           'logged_in'  => TRUE
                        );
                        $this->session->set_userdata($data);
                        redirect('project/view');
                } else     {
                    $this->session->set_flashdata('message', 'The email and password you entered is incorrect, try again.');
                    redirect('login/process');
                }
            }
        }
    }

    function logout()
    {
        $this->session->sess_destroy();
        redirect('home');
    }
}
?&gt;
#14

[eluser]fserrano[/eluser]
Yeah, I'm sure I'm grabbing the right segment. In fact, if I add this line right after setting userdata I see the uri number.
Code:
echo "<p>Current project is ".$this->session->userdata('currentprojectid')."</p>";
However, I then go to the session table and the value appears as "js". I click on a link to see the session var active in another page (using the same echo) and I get "js".

EDIT: Every other session var that was set at login is alive and well both in the database session and if I echo it.
#15

[eluser]bretticus[/eluser]
Sounds like it's being overwritten somewhere then. Perhaps by an ajax call? I agree with @BrianDHall. that is you may need to set up a debugging platform to find it.
#16

[eluser]fserrano[/eluser]
That's what I thought too, but that doesn't seem to be the case. Here's something that will make you crazy: if I set the session to something manually like this it will work fine:

Code:
$this->session->set_userdata('currentprojectid','meh');

How do I go about setting up a debugging platform? Links? Reference?
#17

[eluser]bretticus[/eluser]
Hmmm... then perhaps it's not getting set because of this line (unless your test was in the if statement but even then this may apply...)
Code:
if($this->uri->segment(3)!=NULL){
            $this->session->set_userdata('currentprojectid',$this->uri->segment(3));
            //Update user default project
            $this->db->where('id',$this->session->userdata('userid'));
            $this->db->update('users',array('defaultproject'=>$this->uri->segment(3)));
        } else {
            //Select default project from database
            //redirect('projects/$projectid/');
        }

$this->uri->segment(3) should return a string or boolean false (never NULL. See manual.) It's it's FALSE, it's not NULL. Perhaps if set_userdata gets a FALSE value, it doesn't get set.

As for debugging I recommend netbeans, xdebug and xdebug helper. See setup instructions.
#18

[eluser]BrianDHall[/eluser]
Here is my thread about getting setup with debugging: http://ellislab.com/forums/viewthread/128333/

If you don't have a localhost server the super easiest way is download XAMPP and install it (gives you apache and php and everything), follow instructions linked in my thread for allowing XDebug to load (make sure your phpinfo() shows xdebug being loaded, this wasted a few hours of mine when I downloaded the wrong xdebug for my system under wampserver), then use netbeans and follow the minor instructions for getting it and CI to work with debugging.

The thing is, something is wrong outside of the code you are posting - perhaps in something that was extended, perhaps in a helper, somewhere something is wrong because the session class doesn't have these problems.

My bet is if you try a clean install of CI in another directory and put the basic session code you are trying to make work there, it will work perfectly.

The only good way to narrow it down is either A) backup your program into a zip, then start shredding away at files until you cut whatever is wrong out and therefore get closer and closer to what is doing it, or B) use debugging and step through your code keeping a close eye on what your CI session variables are and checking the trace stack even to see what is going wonky. You may need to step into and out of functions as you go to see what is going wrong.

In short, spending a day getting debugging working will be a less painful day than trying to find the source of what in hell is eating your sessions. The reported behavior of your code and sessions are illogical at best - it ought to work, and does work on our systems, so something is going on behind the scenes.
#19

[eluser]fserrano[/eluser]
Indeed a clean install did the trick. Thanks for your help! It will remain a mistery whatever caused it.
#20

[eluser]SirCharles[/eluser]
I am getting EXACTLY the same mistake....

Code:
function instrucciones()
    {
        global $data;        
        
        $IdCuestionario = $this->uri->segment(3);
// In this case, Year = 2006...
        $Year = $this->uri->segment(4);
        $this->session->set_userdata("Year" , $Year);
        $data['Year']= $Year;
        $this->load->view('view',$data);
}

And when I review the DB Information (I am using database sessions) I get the following:

Code:
1";}s:4:"Year";s:6:"images";}

So now, my Year is "images" ... I get the same error all the time but ONLY en IE7....

After assigning uri to session, the information gets corrupted.... Any information is appreciated...




Theme © iAndrew 2016 - Forum software by © MyBB