Welcome Guest, Not a member yet? Register   Sign In
How to login user automatically after registration

Running CI v 2.0. I want to make it so that when a user registers on my site, upon hitting the submit button not only is the user account created be he is automatically logged in and redirects to the payment page. Right now it's set up so that the user registers and then must login on the next page, then redirects to another page with the payment is made. It seems I am losing some sales with this process, I could streamline it and reduce the number of pages in the checkout and I'm thinking this would help with that. Even though an email activation is sent out right now it seems that it has no effect on whether or not the user can make the payment anyways, so why not just skip this step? Ideally though, I would like to make it so that the user is automatically logged in after creating his account and is redirected to the payment page, can make the payment, but still cannot access his account unless the email activation is made. This way I can still confirm the email AND reduce a page in the checkout process.

My registration setup is like this   mysite.com/auth/register

The user submits his registration info and is sent to mysite.com/auth/login  to log in.

After logging in the user is sent to mysite.com/auth/dahsboard to make a payment.

The code for the autologin function in tank_auth from the libraries folder:

* Login user automatically if he/she provides correct autologin verification
* @return void
private function autologin()
if (!$this->is_logged_in() AND !$this->is_logged_in(FALSE)) { // not logged in (as any user)

if ($cookie = get_cookie($this->ci->config->item('autologin_cookie_name', 'tank_auth'), TRUE)) {

$data = unserialize($cookie);

if (isset($data['key']) AND isset($data['user_id'])) {

if (!is_null($user = $this->ci->user_autologin->get($data['user_id'], md5($data['key'])))) {

// Login user
'user_id' => $user->id,
'username' => $user->username,

// Renew users cookie to prevent it from expiring
'name' => $this->ci->config->item('autologin_cookie_name', 'tank_auth'),
'value' => $cookie,
'expire' => $this->ci->config->item('autologin_cookie_life', 'tank_auth'),

$this->ci->config->item('login_record_ip', 'tank_auth'),
$this->ci->config->item('login_record_time', 'tank_auth'));
return TRUE;
return FALSE;

I have tried to call the autologin() function from the libraries folder within the register function of the auth controller:

if ($this->form_validation->run()) { // validation ok
if (!is_null($data = $this->tank_auth->create_user(
$use_username ? $this->form_validation->set_value('username') : '',
$email_activation))) {
// success


$data['site_name'] = $this->config->item('website_name', 'tank_auth');

I'm probably not even close to how this is done so if someone could point me in the right direction here i would appreciate it. Thanks

Nobody knows how to do this?

you do not need any third-party library. You just have to think a little logic of the application. When you sign up, you send the data needed to perform the functions login. try to think how to do it and show me the code. then I help you. Sorry for my poor english, i'm from Argentina.

Normally to do that just process the logic from your Login method after authentication (user/pass) because you know them from the registration ...
You have all what you need to log your new user his id, username, password..

How ever I suggest not to do that else you may got a lot of bot's at your site Smile
Best VPS Hosting : Digital Ocean

I'll have another look at it when I get a chance. Working on other aspects of the site now.

But in terms of bots, when a user creates an account on my site, he cannot do anything without paying. My accounts are not needing email verification. But the user still needs to pay before being able to do ANYTHING on the site. So how can bots cause me any problems? Haven't had any problems with account sign ups from bots as of yet, and automatically logging in a user would not allow him to do anything bad that I can think of.

(This post was last modified: 02-03-2015, 08:35 PM by user2374.)

Well I got it working, thanks to this post:


Theme © iAndrew 2016 - Forum software by © MyBB