• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting the customer id if session is not set

#1
Hi, sorry for lots questions on auto logins I am just new at that.

I am creating a auto login for my front end system. When the session has expired it unset the customer id.

I use my readAutologin function to see if any rows return with customer id. But because it does not exist in the session or cookie I do not no the better way of being able to get customer id for my readAutologin

My cookie data only has tokens it has no customer id's

PHP Code:
public function readAutologin() {
$this->CI->db->where('customer_id''1');
$query $this->CI->db->get($this->CI->db->dbprefix 'customer_autologin');

if (
$query->num_rows() == 1) {
 
   return $query->row_array();
} else {
 
   return false;
}



I was thinking instead of


PHP Code:
public function readAutologin() {
    $this->CI->db->where('token' $this->CI->input->cookie('remember'));
     $query $this->CI->db->get($this->CI->db->dbprefix 'customer_autologin');
     if ($query->num_rows() == 1) {
            return $query->row_array();
      } else {
            return false;
      }


What is your suggestion?

There is no encryption at the moment I am just playing around to it working?

Full Code Here
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
You can add this to your class:

PHP Code:
// Add this as a class variable
protected static $customerId 0;

// Then to SET it do this
self::$customerId $customer_id;

// Then to GET it do this
$customer_id self::$customerId
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(07-28-2016, 05:19 AM)InsiteFX Wrote: You can add this to your class:

PHP Code:
// Add this as a class variable
protected static $customerId 0;

// Then to SET it do this
self::$customerId $customer_id;

// Then to GET it do this
$customer_id self::$customerId

Do I put the bottom 2 in the __construct() area?
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#4
(07-28-2016, 05:27 AM)wolfgang1983 Wrote:
(07-28-2016, 05:19 AM)InsiteFX Wrote: You can add this to your class:

PHP Code:
// Add this as a class variable
protected static $customerId 0;

// Then to SET it do this
self::$customerId $customer_id;

// Then to GET it do this
$customer_id self::$customerId

Do I put the bottom 2 in the __construct() area?

You first need to get your customers id, I would create two new methods setCustomerId() and getCustomerId()

I see you are getting the customers id in the postLogin method so that would be were you would set it.

You get the customer id anywhere you need it after that.

Also if you do not need the customers id outside of this class then make the variable private.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(07-28-2016, 05:30 AM)InsiteFX Wrote:
(07-28-2016, 05:27 AM)wolfgang1983 Wrote:
(07-28-2016, 05:19 AM)InsiteFX Wrote: You can add this to your class:

PHP Code:
// Add this as a class variable
protected static $customerId 0;

// Then to SET it do this
self::$customerId $customer_id;

// Then to GET it do this
$customer_id self::$customerId

Do I put the bottom 2 in the __construct() area?

You first need to get your customers id, I would create two new methods setCustomerId() and getCustomerId()

I see you are getting the customers id in the postLogin method so that would be were you would set it.

You get the customer id anywhere you need it after that.

Also if you do not need the customers id outside of this class then make the variable private.

Did not work returning 0
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#6
Sorry try this

PHP Code:
static protected $customerId 0
Should not matter but then.

By all means it should be working are you sure that you are returning the customer id?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
(07-28-2016, 06:55 AM)InsiteFX Wrote: Sorry try this

PHP Code:
static protected $customerId 0
Should not matter but then.

By all means it should be working are you sure that you are returning the customer id?

I gave it another go still not work was all way returning 0

Here is what I have done so far. 

The only thing that is stopping me is I cannot get the customer id for readAutologin because session expired. I have all ways been told not to hide customer id or user id in cookies only tokens. So I can not think of any other way to get id.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#8
I'll work something up for you and get back to you later on, using the tokens and database.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#9
(07-29-2016, 05:26 AM)InsiteFX Wrote: I'll work something up for you and get back to you later on, using the tokens and database.

I have worked it out with tokens my self have now got the idea about serialize the tokens in the cookie into array and then encode them then decode them into read part then verify the token that is set in customer with the token that is set in customer autologin and have a key token for extra security.  that would change every so often.

It has been stuffing up my head but now think got it.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#10
All you need to do is save the customer_id to the user_id in the auth_tokens table

You already have the token for that user.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.