Forum Moderators: coopster
This is from the top of my page code:
<?
session_start();
if($_POST['code']!=$_SESSION['string']){
header("Location: login.php?error=1");
}
$username=uc($_POST['username']);
$password=uc($_POST['password']);
if ($password==NULL) {
header("Location: login.php?error=2");
}else{
$query = mysql_query("SELECT username,password FROM tb_users WHERE username = '$username'") or die(mysql_error());
if(mysql_num_rows($query) == 0)
{
header("Location: login.php?error=3");
} else {
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
header("Location: login.php?error=4");
}else{
$query = mysql_query("SELECT username,password FROM tb_users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$nicke=$row['username'];
$passe=$row['password'];
setcookie("usNick",$nicke,time()+7776000);
setcookie("usPass",$passe,time()+7776000);
$lastlogdate=time();
$lastip = getRealIP();
$querybt = "UPDATE tb_users SET lastlogdate='$lastlogdate', lastiplog='$lastip' WHERE username='$nicke'";
mysql_query($querybt) or die(mysql_error());
header("Location: index.php");
?>
<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=index.php">
<?
}
}
}
}
?>
HERE there is some code about styles, tables and pictures used for my login page and next is this:
<?
if($_GET['error'] == 1)
{
print "<b>Error</b> - Wrong Captcha Code<br /><br/>";
}
if($_GET['error'] == 2)
{
print "<b>Error</b> - Please supply a password<br /><br/>";
}
if($_GET['error'] == 3)
{
print "<b>Error</b> - Invalid Username<br><br>";
}
if($_GET['error'] == 4)
{
print "<b>Error</b> - Invalid Password<br /><br />";
}
?>
</span><br>
<form name="form1" method="post" action="">
<table>
<tr>
<td class="midtext">Username:</td>
<td><input type="text" name="username" size="25" class="form" autocomplete="off">
<span class="style12"> *</span></td>
</tr>
<tr>
<td class="midtext">Password:</td>
<td><input type="password" name="password" size="25" class="form" autocomplete="off">
<span class="style12"> *</span></td>
</tr>
<tr>
<td class="midtext" valign="top">Captcha code:</td>
<td class="midtext"><img src="image.php" alt="" onClick="this.src='image.php?newtime=' + (new Date()).getTime();"><br>
(click on the picture to reload)<br />
<input type="text" name="code" size="17" maxlength="17" autocomplete="off" class="form">
<span class="style12"> *</span></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" value="Submit" name="loginsubmit" class="form"></td>
</tr>
</table>
</form>
So where is the problem?
Thanks a lot!
2. when I type "test" as username and "test12" as pass and in the Captcha code form type anything - it will log in again.
So, I never get the message "Wrong captcha code"
[edited by: seedymk at 6:49 pm (utc) on Dec. 30, 2008]
what we need from you is to answer to the questions previously asked.
did you try the test I mentioned, and please, post the image.php script
thanks
Here is the image.php script:
<?php
session_start();
function strrand($length)
{
$str = "";
while(strlen($str)<$length){
$random=rand(48,122);
if( ($random>47 && $random<58) ){
$str.=chr($random);
}
}
return $str;
}
$text = $_SESSION['string']=strrand(5);
$img_number = imagecreate(47,17);
$backcolor = imagecolorallocate($img_number,244,244,244);
$textcolor = imagecolorallocate($img_number,0,0,0);
imagefill($img_number,0,0,$backcolor);
imagestring($img_number,50,1,1,$text,$textcolor);
header("Content-type: image/png");
imagejpeg($img_number);
?>