sdot257
sdot257

Reputation: 10376

Increment session variable by one

How the heck do I increment a variable that's inside a session? If I declare $attempt, each time a user unsuccessfully attempts to login, I want $attempt to increase by 1. In the event it gets to 3, display a captcha.

This doesn't seem to work. :-P

$this->session->set_userdata('attempt',$this->attempt++);

Upvotes: 0

Views: 2351

Answers (3)

Habil M
Habil M

Reputation: 1

After declaring $this->session->userdata('attempt', 0); you can increment the session value using the following code.

$this->session->attempt++;

Upvotes: 0

srinivasan
srinivasan

Reputation: 11

<?php
    $visit=1;
    $view='select * from user_log where id='.$_SESSION['id'];
    $viw=mysql_query($view);
    while($row=mysql_fetch_assoc($viw)){
    $name = $row['name'];
    $visit += $row['visit'];
    $vst = $row['visit'];
    }
    if(!$_SESSION['visit']){
        $update = 'update user_log set visit='.$visit;
        mysql_query($update);                            
        $up_view = $name." you visited ".$visit;         
        $_SESSION['visit']=1;                            
        }
        else                                             
        {
            $up_view = $name." you visited ".$vst;
        }


?>

Upvotes: 1

Seaux
Seaux

Reputation: 3517


$attempt = $this->session->userdata('attempt');
$attempt++;
$this->session->set_userdata('attempt', $attempt);

Upvotes: 2

Related Questions