View Single Post
  #1 (permalink)  
Old December 3rd, 2003, 10:07 AM
Jams30 Jams30 is offline
Authorized User
 
Join Date: Sep 2003
Location: London, , United Kingdom.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jams30
Default Login form question

Hi

I have created a login form for users to access a site. It checks the user name submitted in a form for a match in the database - on correct submission the user is then presented with 'Logged in as $user_name of $co_name, you have logged in $login_no times' - this all works fine. The login form and the welcome message are all in one page login.php.

My question is, how do I stop the user from refreshing the page and thus incrementing the value of $login_no? Here are my thoughts - 1) Create a separate page for the welcome message (plus other information from the database that will be appended to this message) from the login form OR 2)Use sessions - I haven't played around with sessions enough yet to know whether or not they would be any use in this situation.

This is the function that is called depending on the case of a switch statement:

function welcome()
{
$connection = sql_connect();
db_connect();
global $table_name, $user_name, $user_password, $agent_name;
if (empty($user_name))
{
echo "Please enter your User Name<BR>";
login();
exit();
}
elseif (chk_user_name($user_name))
{
echo "Your user name was not recognized! Please re-enter it!<BR>";
login();
exit();
}
elseif (empty($user_password))
{
echo "Please enter your password!<BR>";
login();
exit();
}
elseif (in_use($user_password))
{
echo "Your password is incorrect! Please re-enter it!<BR>";
login();
exit();
}
else
{
global $table_name;
$query = "SELECT * FROM $table_name WHERE user_name = '$user_name'";
$result = mysql_query($query);
$query_data = mysql_fetch_array($result);
extract ($query_data);
$login_no ++;
$query2 = "UPDATE $table_name SET login_no=$login_no WHERE user_name = '$user_name'";
$result = mysql_query($query2);
echo "Logged in as $agent_name of $co_name, you have logged in $login_no times<BR>";
}

}
Presumably, if I need to use sessions, I can add them to my code at a later point?
Note that the form action is set as <?php echo $PHP_SELF ?>.

Any advice would be appreciated

Many thanks

Jamal


Reply With Quote