- Code: Select all
if(isset($_POST["user"]))
{
if($_POST["user"] != "")
{
Certainly functional but a little awkward. I assume you did this to to allow "0". IMO it would be more transparent in the style
- Code: Select all
if ($x || ($x=="0")) {
assuming that does what you want. But really, why bother with a username "0" in the first place?
- Code: Select all
$query = mysql_query("SELECT username, password, admin, last_login,
locked FROM accounts WHERE username='".$_POST["user"]."'");
I wouldn't have even been sure that this would work, but I'd set $user first so that the code would be cleaner and easier to read, like this:
- Code: Select all
WHERE username = '$user'";
I don't know if it's me or generally accepted practice, but I really like to get complex expressions reduced to variables when they need to go in another expression.
- Code: Select all
$r = mysql_fetch_array($query);
I was expecting to see a doublecheck for uniqueness here, although that might be unnecessary. Also, the username is a good place for a regex doublecheck of some sort, at least to eliminate
html tags and a few characters like "-".
- Code: Select all
if(md5($_POST["pass"]) == $r["password"])
{
if($r["locked"] == 0)
You might want an echo of some sort if it's locked.
- Code: Select all
{
* * *
} else $invalid = 1;
} else $invalid = 2;
} else $invalid = 3;
}
Ah I see, you have an error reporting message system I'm not used to. I assume you generate an error statement for the innocent fool, like "please doublecheck the spelling . . . "
The session/cookie section is something I don't know enough about to make even stupid comments. Wish I could be of more help. My general comments would be that:
1. The script would benefit from a layer of validation. Hackers are smarter than I am and I like to give them as much trouble as possible.
2. That the style of concatenating array variables inside a query is easier to deal with if it's cleaned up, e.g.
- Code: Select all
mysql_query("SELECT password, locked FROM accounts WHERE
username='".$session_data[0]."'");
A lot of people seem to do it. Actually, do you need the double quotes? (I don't know, since I don't do this.) And come to think of it, does it even parse? It would just aggravate me to have to deal with
- Code: Select all
."'";
, especially if I had to edit it later on.
3. A small tip: when you post code, preview it and then break lines to eliminate the horizontal scroll bar. It makes it a lot easier to read.