How to pass the session from frontend to backend in joomla site - session

I am in need of using of session to check for login. I set the session at the frontend
and now i need to check the same session at backend so as to check for successful login.
Frontend
$session =& JFactory::getSession();
$session->set('username', "abc123");
backend
$session =& JFactory::getSession();
echo $session->get('username');
But its not displaying the session value, plz help me out? If other solution , you can give it too.

You can check in jos_session table whether user is logged in or not.
The session data is not shared between frontend and backend.
(If you log in frontend and backend with same user, you can see in jos_session table, there are two different session id to same user)

Related

How to check expired seesion data in codeigniter for redirect

I have two user types "Customer" & "Vendor" and I am setting them in session during login process but a little confused on how to achieve a functionality like if the user_type is vendor then when the session timeout automatically so when I click on reload it should be supposed to redirect on the vendor side login.
If user type was customer then after session timeout, if somebody reloads the page it loads the customer side login.
Check session user data then load the page
<?php
if($this->session->userdata('user_type') == 'vendor'){
$this->load->view('vendor_screen'); }
else{
$this->load->view('customer_screen');
}
?>

Password protected pages

I'm wondering how I can password protect pages (therefore web routes) without any auth. My website doesn't have user login/register system, it's not needed.
All I want is to have a several password protected pages that each have a unique password, these passwords are stored in a database.
How would I go about doing this?
Two steps.
create a page for requesting password, also include which page he is trying to access, if user enters the password correctly, set session variable saying pageX is authenticated and redirect to the page.
Create Middleware that checks for the session variable, if it doesn't exist redirect to password page.
I prefer to combine it with javascript window.prompt and session laravel.
Create a pop up to insert the password of the page.
https://www.w3schools.com/js/js_popup.asp
redirect the result to a route, in the controller search the password form database.
use session from laravel, so if the password exist set the session.
https://laravel.com/docs/5.0/session
4.the session isset is null, redirect it to another route.

Using session to reach previous page after login in laravel

I am using Laravel 5.7. For security reasons, I set my laravel application to automatically logout after one hour inactivity. But I want the user log back in the same page before they got kicked out by the system. I try to use Session, but it only store previous url which is the login page url. How can I retrieve that URL before user got automatically logout?
All you need to do is put this in your logout function.
session(['returnUrl' => url()->previous()]);
And then on login function, redirect user to session('returnUrl') and delete session data with session()->forget('returnUrl')
Use this in your login controller
url()->previous()

Check if session has expired in Laravel 5.4

How do I check if the session has expired in laravel 5.4.
If the session has expired I want to show a message.
You can use the following
if(Auth::check()) {
}
Laravel will Create Session For every user no matter the User is Logged in or not. It will create Token for Specific Session. You can check if the Token Exist or not.
You can check if the token is there or not by the function Session::get('_token');.
But if you are asking if You want to check if User's Session is Expired, You can use Auth::check(). It will return if the Session is Expired or not for the specific user.
For example, If the user is Logged in, It will return True or False. But you can't check if overall Session is Expired or not Because Laravel will create and Store Session For every Single Visit No Matter if the user is Authenticated or not.
Let me know if you have any More Questions or Queries regarding Laravel Sessions. Let me know if it Helps!

Using sessions in PHP with native mobile app

I am using CodeIgniter framework at server side to provide backend to a native mobile app. At server side I have to use cart. I am using db for sessions in CodeIgniter. When we use sessions then session_id in cookie of browser let the session work. Mobile app retrieves the session ID from server response after login request is successful - then this session_id can be sent from mobile app to the server in further requests.
Now is there a way in CI to get the data of session on the basis of sessionid? Like if mobile app sends session_id 'xyz' then how can I get the data of session whose session_id is 'xyz'? And how it will be better to work with the session while using cart with it?
Following is my login code. Sessions are being stored in ci_session table of db.
function login($username,$password){
$query = $this->db->select("id,username")->get_where(self::$table, array('username' => $username,'Password'=>$password));
$arr=$query->row_array();
if($arr){
$this->session->set_userdata(array('id'=>$arr['id'],'username'=>$arr['username']));
// $this->db->insert('ci_sessions',array('user_id'=>$arr['id'],'username'=>$arr['username']));
return $this->session->userdata('session_id');
}
return 0;
}
So how can I get session w.r.t. session_id and how can cart work with it? Because I think as in this document: http://codeigniter.com/user_guide/libraries/cart.html cart automatically stores content against loaded session. Therefore I need to load session according to session_id so I can use CIs cart library correctly.
How can I load the session based on session_id, or tell me if I am doing it in a bad way?
First of all, the Question is very bad formatted and written down thus not very understandable...
If I understand it right, here is what You get:
in mobile native app user logs in - a request to a CI based server
CI server logs user in, saves data to session and saves session to the DB while responding to mobile app with session ID
mobile app then sends the session ID whenever a request is send to the server (like when using a cart)
Now - if You have the session stored in the database table ci_session, You only need to request the contents of session stored in the DB table based on session ID provided, so using Your login script example I would do sth similar:
function loadSessionBySessionId($sessionId){
$query = $this->db->select("*")->get_where('ci_session', array('session_id' => $sessionId));
return $query->row_array();
}
Extend the code to meet Your coding convention and server side application. Somewhere else at the server side application where You process the request from mobile app You will check whether the session is returned or not (if no, a FALSE should be returned) and take further actions...
Don't know how Your cart is working - this part is just upon You (unless You make it clear to us what You want us to help You with Your cart).

Resources