-
sanjaya
Junior Member
-
Posts: 46
Threads: 18
Joined: Mar 2018
Reputation:
0
Dear Team. I have develop a app with codeigniter. in my localhost session working fine. but when I host it to real server it's session not set at least minutes.
Please refer below url and demo login details are here..
sghapps.tk
username: [email protected]
Password: Prasanna0311*
-
sanjaya
Junior Member
-
Posts: 46
Threads: 18
Joined: Mar 2018
Reputation:
0
04-11-2018, 10:00 AM
(This post was last modified: 04-11-2018, 10:01 AM by sanjaya.
Edit Reason: name change
)
(04-10-2018, 03:42 AM)InsiteFX Wrote: You need to show your session configuration and how you are setting up your sessions code. This is Config File:-
PHP Code: <?php defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = 'http://www.sghapps.tk/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['cache_query_string'] = FALSE;
$config['encryption_key'] = '';
$config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = NULL; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = ''; $config['cookie_domain'] = ''; $config['cookie_path'] = '/'; $config['cookie_secure'] = FALSE; $config['cookie_httponly'] = FALSE;
$config['standardize_newlines'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE; $config['csrf_token_name'] = 'csrf_test_name'; $config['csrf_cookie_name'] = 'csrf_cookie_name'; $config['csrf_expire'] = 7200; $config['csrf_regenerate'] = TRUE; $config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
This is my Model File:-
PHP Code: <?php Class Login_model extends CI_model { public function __construct() { parent:: __construct(); $this->load->library('session'); }
public function user_create() { $data["user_name"] = $this->input->post('user_name'); $data["email"] = $this->input->post('email'); $data["password"] = $this->input->post('password'); $data["role"] = $this->input->post('role'); $data["status"] = 0; $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'tls://supreme.users.orbitsl.net', 'smtp_port' => '587', 'smpt_user' => '[email protected]', 'smtp_pass' => 'Prasanna0311*', );
$this->load->library('email', $config); $this->email->set_newline("\r\n");
$this->email->from('[email protected]', 'Sanjaya prasanna'); $this->form_validation->set_rules('email', 'Email', 'required|is_unique[app_user.email]'); $this->email->to($data["email"]); // $this->email->cc('[email protected]'); //$this->email->bcc('[email protected]');
$this->email->subject('Email Test'); $this->email->message('Testing the email class.');
if($this->email->send()) { echo "Your Email Has Been Sent."; } else { show_error($this->email->print_debugger()); } $this->db->insert('app_user', $data);
}
function user_data($id) { $query= $this->db->query("SELECT * FROM app_user WHERE id='$id'"); $row = $query->row(); return $row; }
function user_edit($id) { $data["user_name"] = $this->input->post('user_name'); $data["role"] = $this->input->post('role'); $data["status"] = 0; $this->db->where('id', $id); $this->db->update('app_user', $data); }
function user_list() { $query= $this->db->query("SELECT * FROM app_user"); $result = $query->result_array(); return $result; }
public function auth() { $email = $this->input->post('email'); $password = md5($this->input->post('password'));
$query = $this->db->query("SELECT * FROM app_user WHERE email='$email' AND password='$password'");
if($query->num_rows() > 0) { $row = $query->row(); $this->session->set_userdata('NAME', $row->user_name); $this->session->set_userdata('EMAIL', $row->email); $this->session->set_userdata('ID', $row->id); $this->session->set_userdata('STATUS', $row->status=0); $this->session->set_userdata('ROLE', $row->role); //$this->session->set_userdata('PHOTO', $row->image); return true; } else { //$this->session->set_userdata('NAME', 'sessionname'); //$this->session->set_userdata('ID', 'sessionid'); return false; } }
function password_reset() {
$email= $this->input->post("email"); $data['password'] = $this->input->post("password");
$this->db->where('email', $email); $this->db->update('app_user', $data); }
public function login_desable() { $this->session->unset_userdata( 'NAME', 'ID', 'STATUS'); //$this->auth(); //unset($_SESSION['NAME']); } }
This is my session Controller :-
PHP Code: <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct() { parent::__construct(); $this->load->model("Login_model"); $this->load->library('session'); }
public function user_register() { if ($this->session->userdata('NAME')) { $role = $this->session->userdata('ID'); if ($role >=1) { $this->load->helper('form'); $this->load->library('form_validation'); $email["email"] = $this->input->post('email'); if ($this->input->post()) { $this->form_validation->set_rules('user_name', 'Username', 'required|is_unique[app_user.user_name]|min_length[5]|max_length[12]'); $this->form_validation->set_rules('email', 'Email', 'required|is_unique[app_user.email]'); $this->form_validation->set_rules('role', 'User Role', 'required|numeric'); $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]|md5'); $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'trim|required|matches[password]|md5'); $this->input->post(0); if ($this->form_validation->run() === TRUE) { $this->Login_model->user_create(); echo "User has been saved"; redirect('login/app_user_list'); } } $this->load->view('includes/header'); $this->load->view('includes/top_header'); $this->load->view('includes/left_nav'); $this->load->view('login/user_register'); $this->load->view('includes/footer'); $this->load->view('includes/settings'); } else{ $this->session->set_flashdata('message_name', 'You don\'t have permission to access this page'); redirect('user/index'); } } else { $this->session->set_flashdata('message_name', 'Your session has been expired. Please Login'); redirect('login/employee_login'); } }
function app_user_list() { //Check user login information if ($this->session->userdata('NAME')) {
$role = $this->session->userdata('ROLE'); //Check user rights before redirect admin area if ($role >= 1) { $user_data["user"] = $this->Login_model->user_list();
$this->load->view('includes/header'); $this->load->view('includes/top_header'); $this->load->view('includes/left_nav'); $this->load->view('login/user_list', $user_data); $this->load->view('includes/footer'); $this->load->view('includes/settings'); }else{ $this->session->set_flashdata('message_name', 'You don\'t have permission to access this page '); redirect('user/index'); }
} else{ $this->session->set_flashdata('message_name', 'Your session has been expired. Please Login'); redirect('login/employee_login'); } }
function user_update($id) { if ($this->session->userdata('NAME')) { $role = $this->session->userdata('ID'); if ($role >=1) { $this->load->helper('form'); $this->load->library('form_validation'); if ($this->input->post()) { $this->form_validation->set_rules('user_name', 'Username', 'required|is_unique[app_user.user_name]|min_length[5]|max_length[12]'); $this->form_validation->set_rules('role', 'User Role', 'required|numeric'); $this->input->post(0); if ($this->form_validation->run() === TRUE) { $this->Login_model->user_edit($id); echo "User has been saved"; redirect('login/app_user_list'); } } $data["row"] = $this->Login_model->user_data($id); if ($data["row"] == null) { $this->load->view('includes/header'); $this->load->view('includes/top_header'); $this->load->view('includes/left_nav'); $this->load->view('error_page/404'); $this->load->view('includes/footer'); $this->load->view('includes/settings'); } $this->load->view('includes/header'); $this->load->view('includes/top_header'); $this->load->view('includes/left_nav'); $this->load->view('login/user_edit', $data); $this->load->view('includes/footer'); $this->load->view('includes/settings'); } else{ $this->session->set_flashdata('message_name', 'You din\'t have permission to access this page'); redirect('user/index'); } } else { $this->session->set_flashdata('message_name', 'Your session has been expired. Please Login'); redirect('login/employee_login'); } }
public function employee_login() {
$this->load->view('login/login'); }
public function authenticate() { $ok = $this->Login_model->auth();
if ($ok) { $role = $this->session->userdata('ROLE');
if ($role==0){ redirect("user/index"); } elseif ($role>=1){ redirect('dashboard/index'); } } else { $this->session->set_flashdata('message_name', 'Your Email or Password Incorrect'); redirect('login/employee_login'); } //var_dump($ok); die(); }
public function logout() { $this->Login_model->login_desable(); $this->session->set_flashdata('message_name', 'You are successfully logout..'); redirect('login/employee_login'); }
function reset_password() { $this->load->helper('form'); $this->load->library('form_validation'); if ($this->input->post()) {
$this->form_validation->set_rules('email','Current Email Address','trim|required|valid_email[app_user.email]'); $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]|md5'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
if ($this->form_validation->run() === TRUE) { $this->Login_model->password_reset(); redirect('login/employee_login'); } } $this->session->set_flashdata('message_name', 'Your password has been reset'); $this->load->view('login/reset_password'); }
}
-
sanjaya
Junior Member
-
Posts: 46
Threads: 18
Joined: Mar 2018
Reputation:
0
(04-10-2018, 03:42 AM)InsiteFX Wrote: You need to show your session configuration and how you are setting up your sessions code.
I have try this app in another hosting account. its work fine. Any one can help me please. apps.hitnews.lk
-
InsiteFX
Super Moderator
-
Posts: 6,507
Threads: 323
Joined: Oct 2014
Reputation:
239
It's not working because you need to set the sess_save_path
Create a folder called writable under ./applicatiion
PHP Code: $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'pcfx_session_'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = APPPATH.'writable'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE;
SEE: The sess_save_path
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
sanjaya
Junior Member
-
Posts: 46
Threads: 18
Joined: Mar 2018
Reputation:
0
04-15-2018, 08:58 PM
(This post was last modified: 04-15-2018, 08:58 PM by sanjaya.)
(04-15-2018, 08:57 PM)sanjayaI have set as below session path. But same error still there.. Wrote: PHP Code: $config['sess_driver'] = 'database'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = 'ci_session'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE;
(04-11-2018, 02:53 PM)InsiteFX Wrote: It's not working because you need to set the sess_save_path
Create a folder called writable under ./applicatiion
PHP Code: $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'pcfx_session_'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = APPPATH.'writable'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE;
SEE: The sess_save_path
-
InsiteFX
Super Moderator
-
Posts: 6,507
Threads: 323
Joined: Oct 2014
Reputation:
239
If your using the database sessions then the database table name must match
the sess_save_path.
Also make sure that you are using the new CodeIgniter 3.1.8 session table.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
InsiteFX
Super Moderator
-
Posts: 6,507
Threads: 323
Joined: Oct 2014
Reputation:
239
CodeIgniter Users Guide.
Server Requirements
PHP version 5.6 or newer is recommended.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|