Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3612734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:02:16+00:00 2026-05-18T22:02:16+00:00

I have this method: public function activation_code() { //activation code sent into db $activation_code

  • 0

I have this method:

public function activation_code() 
{ //activation code sent into db
  $activation_code = random_string('alnum', 32);
  return $activation_code;
}  

What I’m trying to do is provide this with the post data that gets sent to my database but also provide a copy of that same activation code so I can concatenate it with the “click here to confirm email” url that is in my confirmation email that is sent to users upon registration.

How can I do this? I can’t provide the method because if I do the database code and the email URL code will be different so user wouldn’t be able to match them and confirm their email address.

I’ve tried many other ways such as providing the method in one place e.g.

public function create() 
{ //get post data and insert into db

  $dbcolumn->group_id = 2; //group 1 for admin group 2 for member
  $dbcolumn->first_name = $this->input->post('first_name');
  $dbcolumn->last_name = $this->input->post('last_name');
  $dbcolumn->email = $this->input->post('email');
  $dbcolumn->password = $this->hashed();
  $dbcolumn->birthday = $this->input->post('year') . 
    '-' . $this->input->post('month') . '-' . $this->input->post('day');
  $dbcolumn->sex = $this->input->post('sex');       
  $dbcolumn->activation_code = $this->activation_code();
  // date and time user joined the website
  $dbcolumn->created_on = date('Y-m-d H:i:s', now()); 
  $this->db->insert('users', $dbcolumn);
}

If you look at the dbcolumn->activation code line you’ll see what I’ve done. That works and the code is stored in the database. If I provide the same “$this->activation_code() method to the email that’s sent the codes will obviously be different.

public function send_confirmation_email() 
{ //receives variable from create method
  $this->load->library('email');
  $this->email->from('wengerarsen@gmail.com', 'my site');
  $this->email->to($this->input->post('email'));
  $this->email->subject('my site - Activate your account');
  //copy of activation code returned from create method
  $this->email->message('We\'re back, please click the link to activate your account ' . anchor('http://mysite.com/activation/' . $this->activation_code(), 'Activate my account'));
  $this->email->send();
}

As you can see I have the same method $activation_code() pulled into my send confirmation email method. This will just generate a whole new code meaning I won’t be able to match the database activation code and the URI segment code in the users email.

I have tried to make the variable in the return public and call it in the send confirmaton email method but it doesn’t work. The code ends up missing from he end of the URL in the email.

I’ve tried so many different ways and nothings working.

Maybe I’m missing something here?

Advice, examples etc will be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:02:17+00:00Added an answer on May 18, 2026 at 10:02 pm

    Every time you’re calling activation_code() you’re going to be creating a new code, because you’re only storing it in the scope of that function.

    A better idea would be to store it as an object property, like follows:

    public var $_activation_code = null;
    
    public function activation_code() {
        if (is_null($this->_activation_code)) {
            $this->_activation_code = random_string('alnum', 32);
        }
        return $this->_activation_code;
    }
    

    This will create the code if it hasn’t already been done so for this object, or will simply return the current code if the method has been called more than once, meaning the code will be consistent across the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have this method: public bool CanExecute() And after 70 commits, I added an
I have this factory method in java: public static Properties getConfigFactory() throws ClassNotFoundException, IOException
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
I have this function from a plugin (from a previous post) // This method
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
I have this method Verify_X which is called during databind for a listbox selected
I have this method: private delegate void watcherReader(StreamReader sr); private void watchProc(StreamReader sr) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.