/    Sign up×
Community /Pin to ProfileBookmark

Tracking visitors login trys

I have the following code, but it does not show me in my table increment. It is always 0 in field numtrys. Do you know why?

[code=php]
<?php
// Connect to MySQL-Server
$db=”…”;
$link=mysql_connect (“localhost”, “…”, “…”);
if (!$link)
{
die (“Couldn’t connect to MySQL:”. mysql_error());
}

//Open $db
mysql_select_db (“$db”)
or die (“Couldn’t open $db: “. mysql_error());

$username=strtolower($_POST[‘usernamelogin’]);

$numtrys=$numtrys++;
$query = “INSERT INTO login
SET
`numtrys` = ‘{$numtrys}’ WHERE usernamelogin = ‘$username’ ” ;

mysql_query ($query,$link) or die (“Insert error:”.mysql_error());
echo $numtrys;

?>
[/code]

I would like that each try for login is tracked with increment in the field numtrys for each login attempt.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 07.2005 — that should be an update, not an insert.

however, it's poor logic if you need to monitor failed login attempts. you should get the username and when it happened, not the number of them. you can always do a
<i>
</i>SELECT count(*), <span><code>username</code></span> from <span><code>table</code></span> group by <span><code>username</code></span>;
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 07.2005 — Are you trying to get the whole earth's population logged in? :p your past 300 posts have either been about login or cookies :p

you'll have to define $numtrys first

e.g.:
[code=php]
$numtrys = 0;
[/code]

then increment it this way:
[code=php]
numtrys++;
# not numtrys = numtrys++;
[/code]
Copy linkTweet thisAlerts:
@bokehDec 07.2005 — Is there any sort of logic to the way you are indenting your code? [B]NOT TESTED![/B][code=php]<?php
$db="...";
$link = mysql_connect ("localhost", "...", "...") or die ('Toplisek couldn't connect to MySQL:'. mysql_error());
mysql_select_db ("$db") or die ('Toplisek couldn't open '.$db.': '. mysql_error());
$username = strtolower($_POST['usernamelogin']);
$query = "SELECT numtrys FROM login WHERE usernamelogin = '{$username}'";
$query_result = mysql_query ($query, $link) or die ('Opps Toplisek got it wrong again: '. mysql_error());
mysql_num_rows($query_result) or die('Opps Toplisek got it wrong again: that username doesn't exist');
$result = mysql_fetch_assoc($query_result);
$numtrys = $result['numtrys'] + 1;
$query = "UPDATE login SET numtrys = '{$numtrys}' WHERE usernamelogin = '{$username}'" ;
$query_result = mysql_query ($query, $link) or die ('Opps Toplisek got it wrong again: '. mysql_error());
echo $numtrys;
?>[/code]
Copy linkTweet thisAlerts:
@toplisekauthorDec 07.2005 — Logic is the following: Tracking unwanted visitors

If user has more than 5 trys it will redirect him to help.php. So, unwanted users will be redirected to page where is defined for Lost password. How to do it simple?
Copy linkTweet thisAlerts:
@bokehDec 07.2005 — Logic is the following: Tracking unwanted visitors

If user has more than 5 trys it will redirect him to help.php. So, unwanted users will be redirected to page where is defined for Lost password. How to do it simple?[/QUOTE]
If this is just to help a user I would do it with a session. If you do it with a database don't forget to reset the field back to zero on successful login. Did you try the code I posted?

The following is an example of doing this with a session:[code=php]<?php
$password = 'toplisek';

$form =
'<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'."n".
'Enter password: <input type="password" name="password">'."n".
'<input type="submit" name="submit" value="Vindaloo!">'."n".
'</form>'."n";

session_start();
if(@$_POST['submit']){
if($password != $_POST['password']){
$_SESSION['tries'] = (isset($_SESSION['tries'])) ? $_SESSION['tries'] + 1 : 1 ;
if($_SESSION['tries'] > 4){
header('Location: topliseks_idiots.php');
exit;
}
exit('You have tried to log in '.$_SESSION['tries'].' times now. If you can't '."n".
'get it right within 5 attempts you well be sent to toplisek's idiots page!<br><br>'.$form);
}
exit('Congratulations! You have successfully passed the toplisek intellegence test.');
}
echo $form;
?>[/code]
Copy linkTweet thisAlerts:
@toplisekauthorDec 07.2005 — Thanks Bokeh,

I will use changed your last example.
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...