user3721091 user3721091 - 12 days ago 4
PHP Question

Show Profile Image in Nav bar using codeigniter

I am trying to show user image in navbar top section like Username "Image" just like in this site or any other.

This is what i try.

View

<li class="">
<a href="#" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<img src="<?php echo base_url(); ?>profileimages/<?php if (isset($_SESSION['Prof']))
{
echo $_SESSION['Prof'];
}?>" alt=""><?php echo $admin;?>
<span class=" fa fa-angle-down"></span>
</a>
<ul class="dropdown-menu dropdown-usermenu pull-right">
<li><a href="Profile"> Profile</a></li>
<li><a href="Profile_Setting"> Setting</a></li>
<li><a href="logout"><i class="fa fa-sign-out pull-right"></i> Log Out</a></li>
</ul>
</li>


I am putting the image in session in login model,

Model

public function login_admin($username,$password)
{
$query=$this->db->where(['Username'=>$username,'Password'=>$password])->get('dc_admin');
if($query->num_rows()>0)
{
foreach ($query->result() as $row)
{
$q=$row->Profile_Picture;
$_SESSION['Prof']=$q;
}

$this->session->set_userdata('logged_in',$username);
redirect('Master/Users');
}
else
{
redirect('Master');
}

}


I am new in CI and try to learn, please tell what i can do here to get image, i am able to get the logged IN username but not the image.

Any help will be appreciated.

Answer

I just make a simple change in my code, and follow the session idea by the above Answers. The below code fixed my issue.

 public function login_admin($username,$password)
{
    $query=$this->db->where(['Username'=>$username,'Password'=>$password])->get('dc_admin');
    //this is for single record

    if($query->num_rows()>0)
    {
        $rw = $query->row();
        $q = $rw->Profile_Image;
        $this->session->set_userdata('prfimg', $q);
        $this->session->set_userdata('logged_in',$username);
        redirect('Master/Users');
    }
    else
    {
        redirect('Master');
    }

}
Comments