Hiya,
Thanks for all your help so far - just one small hurdle to surmount now (which sods law dictates will require an entire rewrite!)
Users can log in.
Users can log out.
Users can reset their password so a new one is emailed to them, then when they log in they're asked to change it.
If users enter an incorrect username/password, it says "your details are wrong"
The problem is that if, say, they're on the front page and enter incorrect information, they get the message, then think, actually I'll read this unrestricted article first, they go to another page, use their back button, then get told they need to 'resubmit' the information (which they incorrectly entered initially)
How can I stop this happening?
Here's my code so far:
The code before any of the html:
<?php
require_once('sypphp/includes/common.php');
require_once('sypphp/sypcms/DbConnector3.php');
session_start();
//--- LOG OUT button clicked - destroy session
if ($_GET['action'] == 'logout'){
$_SESSION = array();
session_destroy;
$loggedin=false;
echo '<script language="javascript">
window.location = "news.php"
</script>';
}
//--- LOGIN CHECK - has the user filled in username and password
// or is the user already logged in?
$user = isset($_POST['user']) ? $_POST['user'] : $_SESSION['user'];
$pass = isset($_POST['pass']) ? $_POST['pass'] : $_SESSION['pass'];
//--- NOT LOGGED IN - display login page
if(!isset($user))
{
$loggedin=false;
}
//--- CHECK LOGIN CREDENTIALS
$connector = new DbConnector();
$md5pass=md5($pass);
// build safe query
$logincheck = sprintf('SELECT firstname, surname, reset FROM mem_details WHERE email=%s AND password=%s', quote_smart($user), quote_smart($md5pass));
// run safe query
$loginresult = $connector->query($logincheck) or die ("<br>Error in Query: $query.".mysql_error());
$num= mysql_num_rows($loginresult);
if($num == 1)
{
while ($row = mysql_fetch_array($loginresult)){
$firstname=$row['firstname'];
$reset=$row['reset'];
}
//echo"User logged in";
$_SESSION['user']=$user;
$_SESSION['pass']=$pass;
$_SESSION['auth']=true;
$loggedin=true;
if ($reset==1)
{
echo '<script language="javascript">
window.location = "changepw.php"
</script>';
}
}
else
{
$_SESSION['auth']=false;
}
?>
The code in the include file which changes according to login status:
<?php
if (isset($user) && $loggedin == false || $loggedin == false)
{
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="loginform" id="loginform">
<table width="54%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td colspan="2" align="center" valign="middle"><font size="1"><a href="resetpw.php">Get/Reset Password</a> :: <a href="<?php echo $_SERVER['PHP_SELF']?>?action=logout">Logout</a></font></td>
<td width="26%" align="center"> </td>
</tr>
<tr>
<td width="33%" align="center"><input type="text" name="user" size="10" onFocus="if(this.value=='email')this.value='';">
</td>
<td width="33%" align="center"><input type="password" name="pass" size="10" onFocus="if(this.value=='password')this.value='';"></td>
<td align="center"><input type="submit" name="Submit" value="Login" /></td>
</tr>
<tr>
<td align="center" valign="top"><font size="1">email<br>
</font></td>
<td align="center" valign="top"><font size="1">password<br>
</font></td>
<td align="center"> </td>
</tr>
<?php
if (isset($user) && $loggedin == false)
{
$logintry=true;
$_SESSION = array();
session_destroy;
$loggedin=false;
}
if ($logintry == true)
{
echo '<tr align="left" valign="top">
<td colspan="3">Sorry, either your username or password was incorrect. Please try again, or click above to reset your password</td></tr>';
}
?>
</table>
<?
}
else
{
echo 'Welcome '.$firstname.', you are now logged in!<br>';
echo '<a href="changepw.php">Change password</a> :: <a href="'.$_SERVER['PHP_SELF'] .'?action=logout">Logout</a>';
}
?>
Can someone point me in the right direction please?