Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
time or strtotime() function?
Old 12-05-2008, 08:59 PM time or strtotime() function?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Okay, I am working on my website, and I am starting to implement a failed user logon lock feature, that will lock the user out by ip & name (right now just testing out the ip to make it work) after 5 consecutive logins within a 15 minute period. (right now not important really just want to get it to work )

So anyways I am using Codeigniter for my frame work. The Problem, When I login 5 time purposely to get the function to kick in and work, It does to a point. It will add in the strikes upto 4 (not 5). Or if I set it to 5 in the database it says that I have waited the 15 mins and unbans me automatically.

So here is the trigger

PHP Code:
        if($this->checkLockout($usr) == TRUE){
            
$this->addstrike(5,$usr);
            
$array = array('ip' => $this->input->ip_address());
            
$query $this->db->get_where('lockout',$array);
            
$row $query->row();
            
show_error("Sorry, "$usr ." Your account has been locked out for<strong> 15 minutes</strong>.  It will unlock at <strong>"date('h:m:s',$row->unban) ."</strong><br /> Continuing to try and login during the lockout will increase your ban time by 15 minutes.  So PLEASE WAIT. <br /><br /><br /> Thank you The Admin Staff") ;
            exit();
        }
        
$query $this->db->get_where('users',$array);
        if(
$query->num_rows() !== 1){
            
$ne['username'] = $usr;
            
$nq $this->db->get_where('users',$ne);
            if(
$nq->num_rows() !== 1){
                
show_error("Sorry no user found");
            }
            else{
                
$dur $this->db->get_where('lockout',array('ip'=>$this->input->ip_address()));
                if(
$dur->num_rows() !== 1){
                    
$strike 0;
                }
                else{        
                    
$dur $dur->row();
                    
$strike $dur->strike;
                }
                if(!
$strike){
                    
$strike 1;
                    
$this->addStrike($strike,$usr);                
                    
show_error("Sorry Username / Password combo doesn't match.  You have<b> "$strike ." Out of 5 </b> Login attempts left<br>Once you have reached the limit your ip & account will be banned for 15 minutes for succesive attempts to login");    
                }
                elseif(
$strike >= 5){
                
//    show_error("Sorry, ". $usr ." Your account has been locked out for 15 minutes.");
                    
exit();
                }
                else{
                    
$strike++;
                    
$this->addStrike($strike,$usr);                
                    
show_error("Sorry "$usr ." Username / Password combo doesn't match.  You have<b> "$strike ." Out of 5 </b> Login attempts left<br>Once you have reached the limit your ip & account will be banned for 15 minutes for succesive attempts to login");                }
            } 
And the function

PHP Code:
    private function addStrike($count,$usr)
    {
        
$ip $this->input->ip_address();
        
$array = array('ip' => $ip );
        
$query $this->db->get_where('lockout',$array);
        if(
$query->num_rows() !== 1){
            
$insert = array(
            
//                'id' => '',
                            
'ip' => $ip,
                            
'user' => $usr,
                            
'strike' => $count,
                            
'last_activity' => time(),
                            
'lockout' => 'no',
                            
'unban' => strtotime("+900 seconds"), // 15 Mins to lift
                            
);
            
$this->db->insert('lockout',$insert);
        }
        else{
            
$row $query->row();
            
$strikeCT $row->strike;
            echo 
$count;
            if(
$count <= 4){
                
$update = array(
                            
'ip' => $ip,
                            
'user' => $usr,
                            
'strike' => $count,
                            
'last_activity' => time(),
                            
'lockout' => 'no',
                            
'unban' => strtotime("+900 seconds"), // 15 Mins to lift
                        
);
                
$this->db->where('ip',$ip);
                
$this->db->update('lockout',$update);
            }
            elseif(
$count >= 5){
             echo 
"hi, i am in elseif on addstrike(); ";
                
$update = array(
                            
'ip' => $ip,
                            
'user' => $usr,
                            
'strike' => $count,
                            
'last_activity' => time(),
                            
'lockout' => 'yes',
                            
'unban' => strtotime("+900 seconds"), // 15 Mins to lift
                        
);
                
$this->db->where('ip',$ip);
                
$this->db->update('lockout',$update);
            }
        }
        
/*
        $lockout_data = array(
                'ip' => $ip,
                'user' => $usr,
                'strike' => $count,
                );                            
        $this->session->set_userdata($lockout_data);
        */
    

And this is what I am getting form these functions

Code:
here 1st if
here 2nd if

Time to unban 08:12:27
time now 08:12:32here 3rd if
And it outputs my other output saying invaild password you now have x of 5 strikes. and what not. I guess what I am trying to figure out is HOW IN THE WORLD do I set the time + 15 mins? I tried
PHP Code:
time() + (15 60)
time() + (900)
strtotime("+15 minutes"
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 12-05-2008 at 09:02 PM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
 
Register now for full access!
Old 12-07-2008, 04:37 PM Re: time or strtotime() function?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
So is it windows IIS related??? or just plain I am not getting it?

EDIT:: Okay I got it, I ended up using mktime with the following code

PHP Code:
mktime(date('H'),date('i')+15); 
and were I messed up was I thought m = minute, but nope m = month and i = minutes. SO MUCH CONFUSION. I wont delete the thread or empty it out, just leave it for someone else who may make that mistake.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 12-07-2008 at 05:21 PM.. Reason: resolved
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to time or strtotime() function?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11652 seconds with 12 queries