[eluser]fancy_stuff[/eluser]
Hi there,
here is my code:
I set up a helper file (PEM_session_helper.php) in my application/helper folder:
<?php
function get_user_from_session(){
if(isset($_SESSION['userid']) && $_SESSION['userid']>0)
{
return User->find_by_id($_SESSION['userid']);
}
else{
return null;
}
}
?>
by doing this, I want to retrieve the current user to keep my current session in a controller. Here is the controller:
<?php
session_start();
//This class is made for member account, not including administrator
class My_account extends CI_Controller {
function __construct(){
parent::__construct();
if ($_SESSION['userid'] < 1){
redirect('welcome/index','refresh');
}
}
function index(){
//prep the data
$this->load->helper('PEM_session_helper');
if($current_user = get_user_from_session()){
$data['user_roles'] = $current_user->roles();
echo "lalalala";
$this->load->view('accounts/my_account_view', $data);
}else{
//user not logged in, go back to homepage
redirect('welcome', 'refresh');
}
}
function logout(){
unset($_SESSION['userid']);
unset($_SESSION['username']);
$this->session->set_flashdata('error',"You've been logged out!");
redirect('welcome/index','refresh');
}
}
?>
I am trying to use get $current_user which I want to keep with the session, but the error shows: arse error: syntax error, unexpected T_OBJECT_OPERATOR in C:\xampp\htdocs\project\Peeremed\application\helpers\PEM_session_helper.php on line 6
Can anybody help? Just want to clarify, I have welcome controller with setting session_start() on the top, and have a login function in this controller to verify the user
like this:
function login(){
if ($this->input->post('username')&& $this->input->post('password')){
$udata = $this->input->post('username');
$pdata = $this->input->post('password');
$isLogged = $this->account->verify_member($udata,$pdata);
if (isset($_SESSION['userid']) AND $_SESSION['userid'] > 0){
redirect('account/my_account', 'refresh');
}
$data['main'] = 'accounts/member_login';
$data['title'] = "Peeremed | Member Login";
$this->load->vars($data);
$this->load->view('template');
}
}
Then goes to the beginning controller , my_account.
Hope you know what I am talking, please help if you can. Thanks in advance!
Best,