I would like to solved out the SESSION part in ALL files. SESSION is not working properely anymore. In addition, i need to solved out the javascript errors.
Objective is to access the dashboard.php and other pages from LOGIN.php and CREATEACCOUNT.php WITH validation and SESSION. There are two files: login.php and createaccount.php, from which user comes to dashboard.php in both cases.
When user forgot the password, i need to send password by email AND save new password into the database. I have used md5 method. Please let me know password recovery by email. I have tried so many times to manage ALL the things. It is not working in expected manner.
// js.js
function validateForm()
{
var testemail=document.forms["SignIn"]["txtEmail"].value;
var atpos=testemail.indexOf("@");
var dotpos=testemail.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=testemail.length)
{
alert("Enter Valid Email");
return false;
}
var testpwd=document.forms["SignIn"]["pwd"].value;
if (testpwd==null || testpwd=="")
{
alert("Password must be filled out");
return false;
}
if(testpwd.length<6)
{
alert("Length must be >=6 ");
return false;
}
}
function validatenewuser()
{
var testemail=document.forms["SignUp"]["txtEmail"].value;
var atpos=testemail.indexOf("@");
var dotpos=testemail.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=testemail.length)
{
alert("Enter Valid Email");
return false;
}
var testpassword=document.forms["SignUp"]["pwd"]["cnfmpwd"].value;
var password = document.getElementById(pwd).value;
var confirmpassword = document.getElementById(cnfmpwd).value;
if (password == confirmpassword)
{
alert("Password Match..!!");
return false;
}
else
{
alert("Verify your password");
return false;
}
}
=================================================================================
//createaccount.php
<form method="post" name="SignUp" action="" onSubmit="return validate_newuser();">
<table>
<tr>
<td> Your email address: </td>
<td> <input type="text" id="txtEmail" name="txtEmail" required="required" /> </td>
</tr>
<tr>
<td> Choose your Password: </td>
<td> <input type="password" id="pwd" name="pwd" required="required" /> </td>
</tr>
<tr>
<td> Confirm Password: </td>
<td> <input type="password" id="cnfmpwd" name="cnfmpwd" required="required" /> </td>
</tr>
</table>
<input type="submit" class="btnLogin" value="OK" style="display:inline-block; font-weight:bold; font-size:12px; margin-left:350px;" />
</form>
=================================================================================
//login.php
<form method="post" name="SignIn" action="" onSubmit="return validateForm();">
<table>
<tr>
<td> Enter your Email: </td>
<td> <input type="text" name="txtEmail" /> </td>
</tr>
<tr>
<td> Enter your Password: </td>
<td> <input type="password" name="pwd" autocomplete="off" /> </td>
</tr>
</table>
<input type="submit" class="btnLogin" value="Go" style="display:inline-block; font-weight:bold; font-size:12px; margin-left:350px;" />
</form>
=================================================================================
//dashboard.php + There are other pages like configure.php and profile.php
<?php
session_start();
include "config.php";
include kSERVERPATH."init.php";
?>
<html>
<head>
<script type="text/javascript" src="js.js" media="all" /></script>
</head>
<body>
<?php
$CON // connection works
$txtEmail=$_POST['txtEmail'];
$pwd=$_POST['pwd'];
$cnfmpwd=$_POST['cnfmpwd'];
$encrypt_password=md5($pwd);
$query = " SELECT * FROM `users` WHERE `email` = '".$txtEmail."' ";
$result = mysql_query($query);
$NumResponse = mysql_num_rows($result);
if($NumResponse>0)
{
echo "<script type='text/javascript'>\n";
echo "alert('Already Registered..!! )\n";
echo "</script>";
}
else if($pwd==$cnfmpwd)
{
$query = "INSERT INTO `busyexpe`.`users` (`id_user`, `email`, `ref_lang`, `password`, `date_creation`, `date_updated`, `pwdResetDate`) VALUES (NULL, '".$txtEmail."', '1', '".$encrypt_password."', NOW(), NOW(), NOW());" ;
$result = mysql_query($query) or die(mysql_error());;
echo "<script type='text/javascript'>\n";
echo "alert('Your account has been succesfully created..!!')\n";
echo "</script>";
}
=================================================================================
//logout.php
<?php
session_start();
session_destroy();
header("Location: index.php");
?>
Thanks in advanced.