I need to perform a set of actions after a user successfully logs in. This includes loading data from the database and storing it in the session.
What is the best approach to implementing this?
I need to perform a set of actions after a user successfully logs in. This includes loading data from the database and storing it in the session.
What is the best approach to implementing this?
First of all, move all your PHP code to the top. Without it, my code below wont work.
To do the redirect, use:
header('Location: http://www.example.com/');
Also, please consider my advice. Since it's not the first question today and all your questions are related to basics, you should consider reading some good PHP book to understand how things work.
Here you can find useful links to free books: https://.com/tags/php/info
You need to give the array_shift()
the parameter! Look this example:
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack); // Here you give the parameter
print_r($fruit);
You give the null parameter on array_shift()
and you need to change it!
Update:
array_shift()
shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won't be touched. Read here for more
file_put_contents
creates the file if it doesn't exist, but it fails if you try to put the file in a directory that doesn't exist. So you should try the following:
images
directory exists$target_dir = '/home/ragiththomas/Sites/asco-forum/images/';
You need to define a Spring Bean which implements ApplicationListener.
Then, in your code, do something like this:
public void onApplicationEvent(ApplicationEvent appEvent)
{
if (appEvent instanceof AuthenticationSuccessEvent)
{
AuthenticationSuccessEvent event = (AuthenticationSuccessEvent) appEvent;
UserDetails userDetails = (UserDetails) event.getAuthentication().getPrincipal();
// ....
}
}
Then, in your applicationContext.xml file, just define that bean and it will automatically start receiving events :)
You can add a listener to the
security.interactive_login
event.attach your listener like so. In this example I also pass the security context and session as dependencies.
and in your listener you can store whatever you want on the session. In this case I set the users timezone.