我有两个引导程序模式,一个用于登录,另一个用于注册。它们每个内部都有处理操作的表单(我不在单独的页面中进行操作)。
此项目中包含一个连接页面,用于处理连接的成功和失败。
首先,他们正在工作,但是在添加会话后他们什么也没做,只是将我重定向到同一页面,如果有人可以告诉我是什么原因导致了问题或者我的代码是问题,我将在下面放置代码高兴..问候
session_start();
if(isset($_SESSION['USERNAME']))
{
header('Location:home.php');
}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['signin']))
{
// Get Variables From The Form By Their Name Attributes
$username = $_POST['emailOrMobile'];
$password = password_hash($_POST['password'],PASSWORD_DEFAULT);
// Check if the user exist in database
$stmt = $con->prepare("select ID,firstName,email,mobile,password,status from users where (email=? or mobile =?) and password=?");
$stmt->execute(array($username,$username,$password));
$info=$stmt->fetch();
$count=$stmt->rowCount();
if($count>0)
{
if(!$info["status"]==0)
{
$_SESSION['ID'] = $info["ID"];
$_SESSION['USERNAME'] = $info["firstName"];
header('Location:home.php');
exit();
}
else
{
$_SESSION['ID'] = $info["ID"];
$_SESSION['USERNAME'] = $info["firstName"];
$_SESSION['mobile'] = $info["mobile"];
header('Location:register.php');
exit();
}
}
else
{
header('Location:errors.php');
exit();
}
}
else if(isset($_POST['signup']))
{
// Get Variables From The Form By Their Name Attributes
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$password = password_hash($_POST['password'],PASSWORD_DEFAULT);
$birthDate = $_POST['birthDate'];
if(!empty($_POST['gender']))
{
$gender = $_POST['gender'];
}
else
{
$gender = 0;
}
// Generating serial token for account verification
$tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$serial = '';
for ($i = 0; $i < 4; $i++)
{
for ($j = 0; $j < 5; $j++)
{
$serial .= $tokens[rand(0, 35)];
}
if ($i < 3) {
$serial .= '-';
}
}
// Validate The Form
$formErrors=array(); // Empty Array Defined For Containing Error Messages Of Empty Inputs
if(strlen($firstName) < 3)
{
$formErrors[]='first Name can not be less than <strong>3 characters</strong>';
}
if(strlen($firstName) > 255)
{
$formErrors[]='first Name can not be greater than <strong>255 characters</strong>';
}
if(empty($firstName))
{
$formErrors[]='First Name can not be <strong>empty</strong>';
}
if(strlen($lastName) < 3)
{
$formErrors[]='Last Name can not be less than <strong>3 characters</strong>';
}
if(strlen($lastName) > 255)
{
$formErrors[]='Last Name can not be greater than <strong>255 characters</strong>';
}
if(empty($lastName))
{
$formErrors[]='Last Name can not be <strong>empty</strong>';
}
if(strlen($mobile) > 12)
{
$formErrors[]='Mobile number can not be greater than <strong>12 characters</strong>';
}
if(empty($mobile))
{
$formErrors[]='Mobile can not be <strong>empty</strong>';
}
if(empty($email))
{
$formErrors[]='Email can not be <strong>empty</strong>';
}
if(empty($birthDate))
{
$formErrors[]='Birth Date can not be <strong>empty</strong>';
}
// If There Is No Error Procced The Insert Operation
if(empty($formErrors))
{
// Insert User Info In Database
$stmt = $con->prepare("insert into users (ID , firstName , lastName , email , mobile , password , birthDate , gender , status , token) values (DEFAULT , :ufirstName , :ulastName , :uemail , :umobile , :upassword , :ubirthDate , :ugender , 0 , :utoken)");
$stmt-> execute(array(
'ufirstName' => $firstName,
'ulastName' => $lastName,
'uemail' => $email,
'umobile' => $mobile,
'upassword' => $password,
'ubirthDate' => $birthDate,
'ugender' => $gender,
'utoken' => $serial
)); // Here The Execution Of The Query Ends After Inserting The Variables Inside The Values Defined Teporerly In Query
//$_SESSION['ID'] = $info["ID"];
$_SESSION['USERNAME'] = $firstName;
$_SESSION['mobile'] = $mobile;
header('Location:register.php');
exit();
}
}
}
这是模态代码:
<!-- Signin Popup model -->
<div class="modal fade" id="modal-login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="text-center">LOGIN</h3>
</div>
<div class="modal-body">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
<div>
<input type="text" name="emailOrMobile" required="" autocomplete="off" />
<label>Email or Mobile</label>
</div>
<div>
<input type="password" name="password" required="" autocomplete="off" />
<label>Password</label>
</div>
<button type="submit" class="submit-btn btn btn-block" name="signin">Signin</button>
</form>
</div>
<div class="modal-footer">
<p>Dont have an account?</p>
<button id="join-trigger" class="signup-trigger-btn btn">Signup</button>
</div>
</div>
</div>
</div>
<!-- Signup Popup model -->
<div class="modal fade" id="modal-signup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="text-center">Signup</h3>
</div>
<div class="modal-body">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
<div>
<input type="text" name="firstName" required="" autocomplete="off">
<label>First Name</label>
</div>
<div>
<input type="text" name="lastName" required="" autocomplete="off">
<label>Last Name</label>
</div>
<div>
<input type="email" name="email" required="" autocomplete="off">
<label>Email</label>
</div>
<div>
<input type="tel" name="mobile" required="" autocomplete="off">
<label>Mobile</label>
</div>
<div>
<input type="password" name="password" required="" autocomplete="off">
<label>Password</label>
</div>
<div>
<input type="text" name="birthDate" required="" id="datetimepicker">
<label>Birth Date</label>
</div>
<div>
<div id="gender-div">
<label>Gender</label>
<label class="gender">Male</label>
<label class="gender">Female</label>
<input type="checkbox" name="gender" value="1" />
</div>
</div>
<button type="submit" class="submit-btn btn btn-block" name="signup">SIGN UP</button>
</form>
</div>
<div class="modal-footer">
<p>Already have an account?</p>
<button id="login-trigger" class="signin-trigger-btn btn">Signin</button>
</div>
</div>
</div>
</div>