How to make seperate SESSION for different URLs? - session

Hey guys I'm new to PHP.
I have a login page where I m setting some SESSION and logging in to view my pages.
I have one more login page where I m setting different SESSION values and logging in.
Now on loggin to first page I am able to view pages but when I login with page2 in new tab , page1 starts using SESSION values of page2..
How can I seperate these SESSIONS??

All opened tabs of your browser uses the same session. You need to use different names for your session variables

Related

codeigniter session destroy two different application

For example i am using two admin panel.Once I destroy all session value through one admin panel, another one admin session value also will destroyed . I am using unset and session_destroy for both admin panel. Is this any way to prevent one another
if you are using both panel in the same broswer. Then it will be destroyed. Using different browser might help. That's how session are made to work.
NOTE: Do not use session_destroy(), it destroys all data registered to a session.
So better to use unset(), it unset a given variable passed to the function. Also avoid the same session variable names.
use tow different sessions for admin panels and unset the particular admin session data instead of destroying all session data.

Redirecting all pages in laravel

Ok
So I have a simple page with not many functions as I have been working on the front end but I am now ready to start implementing features and the first feature I want to put in is where a certified admin could press a button on the page and it makes every page redirect to a page that says the site is in maintenance mode
Now I already have the Authentication sorted out for the admin and auth is used.
What could I do?
Create this route:
Route::get('/down', function(){
Artisan::call('down');
});
And then create a button in a view that leads to '/down'. Your website will turn to maintenance mode.
You might want to protect that route with a middleware. To go back to normal mode, you'll have to execute php artisan up in the terminal, since all the website will be frozen.

laravel 4 url redirect cache

In my app, Home is the default Controller set.
I am having a Main controller which redirects to home page if a particular session variable is not set.
After Login validation, session is created for the user and redirects me to home page. On home page when I click on the link to main page "http://domain/main" it redirects the user to home page again.
when i type "http://domain/main/" in the url, it opens the right page. but "http://domain/main" is redirecting to "http://domain/home".
when i clear session files in storage and login "http://domain/main" works but after some time it redirects me to home page again.
I believe there is issue with laravel caching as in my code the redirection handling is perfect.
Sometimes browser caches the redirect 301 url. So in your code if you set session variable on some condition. and you redirect(301) to a page on set of a session variable than your browser caches that redirection.
So if at first session variable is not set, and your code redirects(301) to a different link. next time when you set variable on client interaction and your session variable is set, even than your browser will redirect you to the cached link. to avoid that you must pass redirect http code to the redirectto('location url','302') function in laravel.

Global approach to redirect on login page in MVC3

I want to know how I can design my application using global approach for such scenario
Redirect on login page if user does not authenticated or session has expired
Redirect on login page if user does have other role and try to access page which does not fall under that role.
Redirect on login page if requested for page that does not present in application.
Basically you can create a ActionFilter see this:
http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/understanding-action-filters-cs
Or Another shortcut way to do this in MVC3 you can check Session or authentication in Master page top of the page razor code ie: _LayOut.cshtml like this:
#model CustomerModel{
if(Session["CustomerId"]==null)
RedirectToActionResult("Index","Home");
}
Note: For this you need to inherit all of your views with _LayOut.cshtml and don't inherit /Home/Index view with master page because It will run recursively and you got timeout error.

keeping login sessions with cakephp view caching

I use view caching in my cakephp based cms with generates the cached views for frontend usage.
The frontend checks whether a user is logged or not to show edit options. It works without the view caching enabled, but when enabled it loses the session.
I've put the session code in no cache tags (index.ctp), but there's no session available
<!--nocache-->
$_SESSION['Auth']['User']['username'];
<!--/nocache-->
How can keep the login session when using view caching?
The anwser is to use the cakephp session helper instead of the native php $_SESSION variable
<!--nocache-->
$this->session->read('Auth.user.name');
<!--/nocache-->

Resources