Jump to content

Does this code look ok


mds1256

Recommended Posts

Hello

 

for my website i need to use variables from the select statement located in the code below, e.g. the account status (locked out etc).

 

I hear global variabes are a NO NO.

 

I have utilised session variables, is this the best way to achieve this?

 

The code below sets a sessions variable if the user is locked out but on my home page i have just wrote an 'if' statement is see if this variable matches the criteria (if so then print out the DIV), is there a better way of doing this.

 

 

function loginform($myusername, $mypassword, $ip)
{
$trimmedmyusername = trim($myusername);
if($trimmedmyusername != "")
{
	$sql="SELECT * FROM users, personal_details WHERE users.username='$trimmedmyusername' and users.password='$mypassword' AND users.username = personal_details.username";

	$result=mysql_query($sql);
	$count=mysql_num_rows($result);
	$row = mysql_fetch_array($result, MYSQL_BOTH);

	if(lockout($trimmedmyusername)==1)
	{
		$_SESSION['accountstatus'] = "lockedout";
	}
	elseif($count==1)
	{
		$_SESSION['myusername'] = $trimmedmyusername;
		$_SESSION['mypassword'] = $mypassword;
		$_SESSION['myname'] = $row['firstname'];
		$_SESSION['lastname'] = $row['lastname'];
		$_SESSION['title'] = $row['title'];
		$_SESSION['lastlogin'] = $row['lastlogin'];
		unset($_SESSION['accountstatus']);
		loginsucess($trimmedmyusername, $mypassword, $ip);
	}
	else 
	{
		unset($_SESSION['myusername']); 
		$_SESSION['myusername'] = $trimmedmyusername;
		loginfail($trimmedmyusername, $mypassword, $ip);
		$_SESSION['accountstatus'] = "incorrectdetails";
	}
}
else
{
	unset($_SESSION['accountstatus']);
	unset($_SESSION['myusername']);
	echo "Please enter a username";
}

}

 

<?php
	if(isset($_SESSION['accountstatus']))
	{
		accountstatus($_SESSION['accountstatus']);
	}
	else
	{
		accountstatus("");
	}
?>

 

function accountstatus($status)
{
if($status == "lockedout")
{
	echo "<div id='lockedoutimage' style='background:url(lockedout.jpg) no-repeat;'></div>";
}
elseif($status == "incorrectdetails")
{	
	echo "<div id='lockedoutimage' style='background:url(incorrect.jpg) no-repeat;'></div>";
}
else
{
	echo "";
}
}

Link to comment
https://forums.phpfreaks.com/topic/217448-does-this-code-look-ok/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.