Azazeal
10-22-2003, 09:31 PM
Hi Folks.
This is a log in page that I coded today. The concept behind the database is:
1. One database contains user names, passwords and a surveyID
2. The other database contains the URL to the survey.
Which the reason for the two queries.
I believe this works as it stands, but would like some opinions and ideas.
The only part I haven't completed would be an error message of sorts, if the username and pw is wrong.
For that I was thinking of using another switch on $result from the first query.
Thanks for any suggestions you may have.
<?php
$log_in = $_POST['Submit'];
$FormUserName = $_POST['FormUserName'];
$FormUserPass = $_POST['FormUserPass'];
//--Clean Data
$FormUserName = strip_tags($FormUserName);
$FormUserPass = strip_tags($FormUserPass);
$LFormUserName = strlen($FormUserName);
$LormUserPass = strlen($FormUserPass);
$authorized = '0';
//-Check for existence of input from user
if($log_in)
{
switch($log_in)
{
case !$FormUserName || !$FormUserPass:
$error = "Please fill out both fields";
break;
//--Leave commented out unless there is a length restriction on user input --//
//case $LuserName < 5:
// $error = "Your username is too short";
//break;
//case $LuserPass < 5:
// $error = "Your password is too short";
//break;
case $FormUserName && $FormUserPass:
require_once("dbincludes/db_connect.inc.php");
mysql_connect($db_server, $db_user, $db_password) or die("Cannot connect");
mysql_select_db($db_database) or die("Could not choose database");
$query = mysql_query("select * from $db_user_table where userName = '$FormUserName' and userPass = '$FormUserPass' ");
$result = mysql_num_rows($query);
while($userInfo=mysql_fetch_array($query))
{
$DBUserName = $userInfo['userName'];
$DBUserPass = $userInfo['userPass'];
$surveyID = $userInfo['surveyID'];
}
break;
}
}
if($authorized=='1')
{
$query = mysql_query("SELECT * from $db_survey_table WHERE surveyID = '$surveyID' ");
while($d=mysql_fetch_array($query))
{
$url = $d['URL'];
header("Location: $url");
}
//--Debug echo $url;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Log In: </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<link href="style.css" rel="stylesheet" type="text/css">
</HEAD>
<body>
<form name="" method="post" action='<?php $_SERVER['PHP_SELF']?>''>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/top.gif" width="343" height="24"></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="boxborder"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td colspan="3">Please enter your login information.</td>
</tr>
<tr>
<td width="35%"> </td>
<td width="65%" colspan="2"> </td>
</tr>
<tr>
<td align="right" valign="middle">User Name:</td>
<td colspan="2"><input name="FormUserName" type="text" size="20" maxlength="20" value='<?php echo $FormUserName; ?>'></td>
</tr>
<tr>
<td align="right" valign="middle">Password:</td>
<td colspan="2"><input name="FormUserPass" type="password" size="20" maxlength="6"></td>
</tr>
<tr>
<td colspan="3"> <table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="50%" align="right" valign="middle"><input type="reset" name="reset" value="Reset"></td>
<td width="50%" align="left" valign="middle"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/bottom.gif" width="343" height="24"></td>
</tr>
</table></td>
</tr>
</table>
<table align="center">
<tr>
<td align="center" class="error"><?php echo $error; ?></td>
</tr>
</table>
</form>
</body>
</html>
This is a log in page that I coded today. The concept behind the database is:
1. One database contains user names, passwords and a surveyID
2. The other database contains the URL to the survey.
Which the reason for the two queries.
I believe this works as it stands, but would like some opinions and ideas.
The only part I haven't completed would be an error message of sorts, if the username and pw is wrong.
For that I was thinking of using another switch on $result from the first query.
Thanks for any suggestions you may have.
<?php
$log_in = $_POST['Submit'];
$FormUserName = $_POST['FormUserName'];
$FormUserPass = $_POST['FormUserPass'];
//--Clean Data
$FormUserName = strip_tags($FormUserName);
$FormUserPass = strip_tags($FormUserPass);
$LFormUserName = strlen($FormUserName);
$LormUserPass = strlen($FormUserPass);
$authorized = '0';
//-Check for existence of input from user
if($log_in)
{
switch($log_in)
{
case !$FormUserName || !$FormUserPass:
$error = "Please fill out both fields";
break;
//--Leave commented out unless there is a length restriction on user input --//
//case $LuserName < 5:
// $error = "Your username is too short";
//break;
//case $LuserPass < 5:
// $error = "Your password is too short";
//break;
case $FormUserName && $FormUserPass:
require_once("dbincludes/db_connect.inc.php");
mysql_connect($db_server, $db_user, $db_password) or die("Cannot connect");
mysql_select_db($db_database) or die("Could not choose database");
$query = mysql_query("select * from $db_user_table where userName = '$FormUserName' and userPass = '$FormUserPass' ");
$result = mysql_num_rows($query);
while($userInfo=mysql_fetch_array($query))
{
$DBUserName = $userInfo['userName'];
$DBUserPass = $userInfo['userPass'];
$surveyID = $userInfo['surveyID'];
}
break;
}
}
if($authorized=='1')
{
$query = mysql_query("SELECT * from $db_survey_table WHERE surveyID = '$surveyID' ");
while($d=mysql_fetch_array($query))
{
$url = $d['URL'];
header("Location: $url");
}
//--Debug echo $url;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Log In: </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<link href="style.css" rel="stylesheet" type="text/css">
</HEAD>
<body>
<form name="" method="post" action='<?php $_SERVER['PHP_SELF']?>''>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/top.gif" width="343" height="24"></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="boxborder"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td colspan="3">Please enter your login information.</td>
</tr>
<tr>
<td width="35%"> </td>
<td width="65%" colspan="2"> </td>
</tr>
<tr>
<td align="right" valign="middle">User Name:</td>
<td colspan="2"><input name="FormUserName" type="text" size="20" maxlength="20" value='<?php echo $FormUserName; ?>'></td>
</tr>
<tr>
<td align="right" valign="middle">Password:</td>
<td colspan="2"><input name="FormUserPass" type="password" size="20" maxlength="6"></td>
</tr>
<tr>
<td colspan="3"> <table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="50%" align="right" valign="middle"><input type="reset" name="reset" value="Reset"></td>
<td width="50%" align="left" valign="middle"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/bottom.gif" width="343" height="24"></td>
</tr>
</table></td>
</tr>
</table>
<table align="center">
<tr>
<td align="center" class="error"><?php echo $error; ?></td>
</tr>
</table>
</form>
</body>
</html>