Jump to content

stopping infinite loop


RalphLeMouf

Recommended Posts

I am building a social network via code igniter. Upon registration, the potential member get's stored in the db, and their status get's marked to pending. I then send them a confirmation email with a hashed token link. When they hit the link it marks their account as active and takes them to a welcome page that has a sign in.

 

When I go to the link it sets of an infinite loop and freezes my computer when I'm working on my MAMP. ( or I'm suspicious that it's an infinite loop )

 

Here is my pertinent code:

 

auth CONTROLLER that sends the email:

 

function varification_email()
{
    $query = $this->db->query('SELECT * FROM users order by id desc LIMIT 1');
    $token = sha1($user->email.$user->salt).dechex($user->id);
    $domain = "clci.dev/index.php";
    $link = "http://www.".$domain."/account/confirmation/?token=$token";
    foreach ($query->result() as $user)
    {
        $this->load->library('email');

        $this->email->from('noreply@cysticlife.org', 'CysticLife');
        $this->email->to($user->email); 

        $this->email->subject('Welcome to CysticLife!');
        $this->email->message("Thanks for signing up for CysticLife! To complete the registration process please go to the following web address:\n\n$link\n\n-Your friends at CysticLife\n\nPlease remember to add the cysticlife.org domain to your address book to ensure that you receive your CysticLife e-Notifications as requested.eh");    

        $this->email->send();
}

account CONTROLLER that the user is linked back to from the email:

 

public function confirmation() {
    $data['main_content'] = 'account/confirmation';
    $this->load->view('includes/templates/main_page_template', $data);
    $this->load->library('encrypt');
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->model('user_model', 'um');
    $login = $this->input->post('submit');


    //IF THE SUBMIT BUTTON IS TRIGGERED THE POST DATA IS SENT TO THE VALIDATE FUNCTION IN THE MODEL VIA VARIABLES CREATED 
    if($login) {
        $user = $this->um->validate(array('email' => $this->input->post('email')));
        if( $user ) {
            // CHECK THE USER'S PASSWORD AGAINST THE ONE FROM THE LOGIN FORM
            if($user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password')))) {
                $this->session->set_userdata('logged_in', TRUE);
                $this->session->set_userdata(array(
                    'email' => $this->input->post('email')
                ));
                $this->session->userdata('logged_in');
                redirect('account/dashboard');
                exit;
            }
        }
    }

    $this->index();
}

 

 

Thanks in advance

Link to comment
Share on other sites

If you let it run it should time out, giving you an error message with the line number it was on when the timeout occurred. Should give you something more to go on.

If your computer just locks up, then there's something else going on. Either a problem with the software stack, or with the hardware. Pretty hard to get a PHP script to crash a PC, without there being something wrong with the underlying stuff in the first place.

 

PS: The following line seems a bit out of place:

$this->session->userdata('logged_in');

Link to comment
Share on other sites

I'm actually on a MAC, so not sure if that would make a difference or not. I really can't see anything that would make a difference.

 

As far as the variable I created that you said is out of place. Apparently I'm doing it wrong but I'm basically trying to start a session based off the users id that is stored in the db and store that in a variable to use with if statement, and or / be used to determine whether the user is logged in to load different views and things like that.

 

would you happen to have a good recommendation on how to do that?

 

thanks

Link to comment
Share on other sites

A Mac is still a (Personal) Computer, so no; No difference at all.

 

Unfortunately I am not familiar with how CI works, so I'm afraid I cannot give you any specific help on how to design your code for it. I'm also a bit confused on what it is that you're really trying to do. "Starting a session based off the users ID" is a bit vague, unless you mean you want to start a session and then store the user's ID in the session array? In which case, it's straight forward.

Then again, I don't know how CI works, so I don't know what hoops you have to jump through with it.

 

Reason I thought that the function call looked out of place was because of it's completely non-descriptive name, and the fact that you've called set_userdata () just a few lines above with almost the same parameters.

I don't know whether it's standard CI, or if you've chosen the name, but userdata () is a terrible name for a function. Rather good name for a variable containing the user's data, however, but that's something entirely different.

Link to comment
Share on other sites

@"Apparently I'm doing it wrong...". 

 

You don't implicitly start a session, the bootstrap does all that for you - even guests get sessions.  What you want to do is add parameters to it as to distinguish guest from validated user. 

 

Your code bothers me at this point:

$this->session->set_userdata('logged_in', TRUE);
$this->session->set_userdata(array( 'email' => $this->input->post('email') ));
$this->session->userdata('logged_in');

 

$this->session->userdata() is an array, so you want to send it key, value pairs, not another array.  If you dumped your array, it'd look like:

 

[userdata] (Array)

[logged_in] => 1

[0] => => blah blah

 

So I'm still not sure why you send an array, i swear i've said that before.

 

Anyway, i don't know what you're doing with $this->session->userdata('logged_in');, the session's userdata() function returns a value, and you're not doing anything with it.

 

I suspect your loop is in your home/dashboard where it's checking for a session value that doesn't exist and you're running in circles.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.