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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.