我有一个登录管理面板。我用php创建了一个登录页面, html,java脚本。我使用session将用户传递到下一页。这完全适用于我的localhost。但是在实时服务器上我遇到了问题,它显示我已经成功了#34;弹出并重定向回登录页面。当我在localhost上打印会话时,它显示我的会话值,但在实时服务器上它是空的。我已经搜索了很多答案并尝试了同样的但仍然无法正常工作。请帮助并感谢您的时间和考虑。
我的直播服务器是 Apache HTTP Server版本2.2
我的连接文件 db.php 是
<?php
/*Default time zone ,to be able to send mail */
date_default_timezone_set('Asia/Kolkata');
//connect database
$con = mysqli_connect ("localhost","rootuser","password","testdbname"); //host, username, password, database name
//database connect error
if (mysqli_connect_errno())
{
echo "Failed to connect to MySql: " . mysqli_connect_errno();
}
?>
login.php 文件
<?php
session_start();
include("includes/db.php");
if(isset($_SESSION['mysesiuid']))
{
header('Location: index.php?alreadyin');
//echo "<script>window.location.assign('index.php?alreadyin')</script>";
}
else
{
?>
<script src="assets/js/validate/jquery.js" type="text/javascript"></script>
<script>
//login script
$(document).ready(function() {
var mazalagna_login_email1 = 1;
var mazalagna_login_email2 = 1;
var mazalagna_login_email3 = 1;
var mazalagna_login_password = 1;
$("#main_login_submit").click(function(){
//password
if($("#mazalagna_pass").val() == ''){
$("#mazalagna_pass").css("border","1px solid red");
$("#mazalagna_password_error").show();
mazalagna_login_password = 1;
}else{
if($("#mazalagna_pass").val().length < 6){
$("#mazalagna_pass").css("border","1px solid red");
$("#mazalagna_password_length_error_longform").show();
$("#mazalagna_password_error").hide();
mazalagna_login_password = 1;
}else{
$("#mazalagna_pass").css("border","1px solid green");
$("#mazalagna_password_length_error_longform").hide();
$("#mazalagna_password_error").hide();
mazalagna_login_password = 0;
}
}
//email
var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
var validateMazalagnaEmail = pattern.test($("#mazalagna_email").val());
if($("#mazalagna_email").val() == ''){
$("#mazalagna_email").css("border","1px solid red");
$("#mazalagna_email_error").show();
mazalagna_login_email1 = 1;
}else{
$("#mazalagna_email").css("border","1px solid green");
$("#mazalagna_email_error").hide();
mazalagna_login_email1 = 0;
}
if(!validateMazalagnaEmail){
$("#mazalagna_email").css("border","1px solid red");
$("#mazalagna_email_error").show();
mazalagna_login_email2 = 1;
}else{
$("#mazalagna_email").css("border","1px solid green");
$("#mazalagna_email_error").hide();
mazalagna_login_email2 = 0;
}
if(validateMazalagnaEmail){
$.ajax({
type: "POST",
cache: false,
url: "php/ajax_email_exist.php",
data: { email: $("#mazalagna_email").val()},
success: function (data)
{
if(data != 1){
$("#mazalagna_email").css("border","1px solid green");
$("#mazalagna_exist_email_error").hide();
mazalagna_login_email3 = 0;
}else{
$("#mazalagna_email").css("border","1px solid red");
$("#mazalagna_exist_email_error").show();
mazalagna_login_email3 = 1;
}
if(mazalagna_login_email1 == 0 && mazalagna_login_email2 == 0 && mazalagna_login_email3 == 0 && mazalagna_login_password == 0 ){
$.ajax({
type: "POST",
cache: false,
url: "main_login.php",
data: {
username1: $("#mazalagna_email").val(),
password1: $("#mazalagna_pass").val()
},
success: function (data)
{
alert(data);
//alert("Welcome! You have loged in successfully!");
window.location.replace("index.php");
}
});
}
}
});
}
//edit value
$(".regval").click(function(){
var id = "#"+$(this).attr("id");
var errorId = "#"+$(this).attr("id")+"_error";
$(id).css("border","1px solid #a39e9e");
$(errorId).hide();
});
});
});
</script>
<strong> Enter Details To Login </strong>
<!-- <form role="form" action="" method="post"> -->
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-tag" ></i></span>
<input type="text" id="mazalagna_email" name="mazalagna_email" class="form-control regval" placeholder="Your Username" required />
</div>
<div id="mazalagna_email_error" style="display:none; margin-top:-12px; margin-bottom:12px; text-align:center; color:red; font-size:12px;">Please enter valid Email</div>
<div id="mazalagna_exist_email_error" style="display:none; margin-top:-12px; margin-bottom:12px; text-align:center; color:red; font-size:12px;">Your email id is not registered.</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-lock" ></i></span>
<input type="password" id="mazalagna_pass" name="mazalagna_pass" class="form-control regval" placeholder="Your Password" required />
</div>
<div id="mazalagna_password_error" style="display:none; margin-top:-12px; margin-bottom:12px; text-align:center; color:red; font-size:12px;">Please enter your password</div>
<div id="mazalagna_password_length_error_longform" style="display:none; margin-top:-12px; margin-bottom:12px; text-align:center; color:red; font-size:12px;">Enter min 6 character password</div>
<button type="submit" id="main_login_submit" name="main_login_submit" class="btn btn-primary ">Login Now</button>
<hr />
<!-- </form> -->
<?php } // top else close here ?>
我的 main_login.php 文件是
<?php
//connect database
session_start();
require_once 'includes/db.php';
global $con;
$user_email = trim($_POST['username1']);
$user_password = trim($_POST['password1']);
$password = mysqli_real_escape_string($con, md5($user_password));
$res = $con->query("SELECT * FROM useradmins WHERE email='$user_email' AND password='$password'");
$row = $res->fetch_assoc();
$uid = $row['admin_id'];
$name = $row['name'];
$useremail = $row['email'];
$pass = $row['password'];
if($useremail==$user_email && $pass==$password){
$_SESSION['mysesi']=$name;
$_SESSION['mysesiuid']=$useremail;
echo "Loged in successfully.";
//update status and login time
date_default_timezone_set('Asia/Kolkata');
$date_email = date('F j, Y h:i A');
$date = date('Y-m-d H:i:s');
$user = $_SESSION['mysesiuid'];
$ip = $_SERVER['REMOTE_ADDR'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];
$update_last_login="UPDATE useradmins SET admin_status='ONLINE',active_ip_address='$ip',admin_last_login='$date' WHERE admin_id='$user'";
$update_last_login = mysqli_query($con, $update_last_login);
}
else{
echo "Unable to login.";
}
?>
index.php 文件
<?php
session_start();
require_once 'includes/db.php';
if(!isset($_SESSION['mysesiuid']))
{
header('Location: login.php');
exit;
}
else
{
?>
<h1>hi success</h1>
<?php } ?> <!-- top else statement close here -->