I am making a site whereby i have a functions page that acts as a template for my site with functions defining specific areas of the site, into these areas i include specific php files, for example there is a section for members to login which loads as login_form.php.
I am adapting some old code i have written and i need basically to mould two scripts into one, at the moment my login_form.php posts data to checkuser.php which responds accordingly, either by declaring that there is data missing, that the data is incorrect or accepting the data. i need to make it so that these responses take place within login_form.php as this is the designated login section, at the moment these responses are happening within the body of the page and this confuses things a little.
login_form.php
echo '
<?
<form action="checkuser.php" method="post" name="" id="">
<table width="160" height="140" border="0" align="center" cellpadding="0" cellspacing="4">
<tr>
<td colspan="2" class="loginText"><em class="loginTextClick">lost your password? click <a href="lostpw.php">here</a></em></td>
</tr>
<tr>
<td align="right"><span class="loginText">Username: </span></td>
<td align="left"><input name="username" type="text" id="username" size="12" maxlength="30"></td>
</tr>
<tr>
<td align="right"><span class="loginText">Password: </span> </td>
<td align="left"><input name="password" type="password" id="password2" size="12" maxlength="30"></td>
</tr>
<tr>
<td height="28"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
';
?>
checkuser.php
<?
/* Check User Script */
session_start(); // Start Session
include 'db.php';
require 'functions.php';
$pagename = 'seen';
pagetop($pagename);
pageTopDown();
loginSection();
// Convert to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
//include 'login_form.php';
pageMiddle();
topBox();
betweenBoxes();
bottomBox();
pagebottom();
exit();
}
// Convert password to md5 hash
$password = md5($password);
// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
session_register('first_name');
$_SESSION['first_name'] = $first_name;
session_register('last_name');
$_SESSION['last_name'] = $last_name;
session_register('email_address');
$_SESSION['email_address'] = $email_address;
session_register('special_user');
$_SESSION['user_level'] = $user_level;
mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
header("Location: login_success.php");
}
} else {
echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />
Please try again!<br />";
include 'login_form.html';
pageMiddle();
topBox();
betweenBoxes();
bottomBox();
pagebottom();
}
?>
Thanks a lot.