Jump to content

[SOLVED] Login Form Help


ckehrer

Recommended Posts

Hi,

 

Just a quick question. I'm working on a social_network site for a certification consisting of pages login, join, edit, profile ect. Below is code for the login page, but my problem is when the page is loaded the email and password fields on all pages instead of being blank are displaying my personal account email and password information. No ideas why this is happening. Any help would be appreciated.

 

Thanks,

Charlie

 

<?php

#login.php -- interface for logging into the social networking site

#first, if a member's already logged in, redirect to the profile page.
session_start();

if ($_SESSION['memberID']) {
#if already logged in, redirect
header("Location: /social/profile.php");
exit();
}

else {

if(count($_POST) > 0) {
$host = "myhost";  //yourlogin should be your Sandbox login
$user = "username";           
$pw = "userpw";      
$database = "database";   
$table_1 = "member_login";
            
$db = mysql_connect($host,$user,$pw)
     or die("Cannot connect to mySQL.");
                
mysql_select_db($database,$db)
     or die("Cannot connect to database.");

$email = $_POST['email'];
$password = $_POST['password'];

#only check if someone has submitted an email or a password
if ($email || $password) {
   #make sure both exist
   if (!($email)) {
     $error_message = "Please enter the email address you used to join.  ";
   }
   else if (!($password)) {
     $error_message = "Please enter your password.  ";
   }
   else {
     #now, check the database for a correct login
     $command = "SELECT memberID FROM $table_1 WHERE email='".addslashes($email)."' 
                 AND password=password('".addslashes($password)."');";
     $result = mysql_query($command);
     if ($data = mysql_fetch_object($result)) {
        #correct login!  Set cookie and redirect.
        $_SESSION['memberID'] = $data->memberID;
        header("Location: /social/profile.php");
     }
     else {
        $error_message = "Sorry, your login was incorrect.  Please contact us if you've forgotten your password.";
     }
   }
}

}
#a nice-looking header 
include($_SERVER['DOCUMENT_ROOT']."/.php_files/social_header.inc");
?>

<h4>Log in to access your profile and connect to others!</h4>
<span style="color:red;font-size:12px;">
<?
if ($error_message) {
   echo $error_message;
}
?>
</span>

<form method=POST action="/sql2_final/login.php">
<table>
<tr>
<td align=right>
Email address:
</td>
<td align=left>
<input type=text size=24 max=50 name="email" value="<? echo htmlentities($email); ?>">
</td>
</tr>
<tr>
<td align=right>
Password:
</td><td align=left>
<input type=password size=12 max=12 name="password" value="">
</td>
</tr>
<TR>
<TD colspan=2 align=center>
<input type=submit value="SUBMIT">
</TD></TR>
</TABLE><br>
Not a member?  <a href="join.php">Click here</a> to join!
</form>

<?php }

#a nice-looking footer 
include($_SERVER['DOCUMENT_ROOT']."/.php_files/social_footer.inc");

?> 

Link to comment
https://forums.phpfreaks.com/topic/176396-solved-login-form-help/
Share on other sites

You can't really fix it no, because it isn't broken  :P, if you mean can you stop it then the answer is a little more murky. There have been a few threads on the forum recently (I've only been here a few days, so there's probably an awefully lot of them) asking this question. To my knowledge there is the non-standard autocomplete attribute <input type="text" autocomplete="off" />, but I don't believe it always works. I've got a feeling my banks site uses JavaScript to clear the box after the page has loaded, but obviously theres no guarantee the user has JavaScript enabled. I suggest tryin to search the forum and see what you can come up with.

Archived

This topic is now archived and is closed to further replies.

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