试图重定向到index1.php页面

时间:2015-03-04 03:41:39

标签: php mysql

第一次来这里 我知道有人必须来这里遇到像我这样的问题,但请相信我,我已经在搜索这个网站上遇到了与我类似的问题,但实际上找不到我的问题。问题是我使用WAMP服务器,我的网站运行正常。

在WAMP上,我有index.php(具有登录表单),我有login.php(连接到数据库并验证登录详细信息),我有index2.php(我应该是重定向也),我也有注销,php(它会破坏会话),我有session.php

所有这一切都在我的WAMP服务器上完美运行,但当我将其上传到实时服务器时,我甚至无法登录,经过一些小小的调整,我可以登录但是我得到一个空白页面,因为我卡在登录。 php页面,我没有重定向到index2.php

在WAMP上,我使用(“localhost”,“root”,“”,“modem”) 但对于我的直播服务器,我使用(“localhost”,“alagbeco”,“a12345”,“alagbeco_modem”)

我的脚本

的index.php

    <?php
    include('login.php'); // Includes Login Script

    if(isset($_SESSION['login_user'])){
    header("location: index2.php");
    }
    ?>

    <html>
    <head>
<title>SEAP Divisional Monthly Subscription Database</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#E6E6FA">

<br>


<div>
    <div style="float: left; margin-left: 340px;>
    <a href="index.html"><img src="image/banner.png" alt="" align=""/></a>
</div>
<br><br><br><br><br><br><br><br>



<div style="float:left; border:2px solid #ccc; padding:10px 40px 25px; border-radius:10px; margin-left:500px; width:250px; margin-top:0px;">
<h3>Login Here</h3>
<form action="" method="post">
<label>Username :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" type="password">
<br><br><br>
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
<a href="reset.php">Change password</a>
</div>
<br><br>


</body>
</html>

index2.php

<?php
include('session.php');
?>

<head>

<style type="text/css">

    ul{

        padding-left: 0px;

        list-style: none;

    }

    ul li{

        float: left;

        width: 200px;

        text-align: center;

    }

    ul li a{

        display: block;

        padding: 5px 10px;

        color: #FFF;

        background: #0101DF;

        text-decoration: none;

    }

    ul li a:hover{

        color: #000000;

        background: #F7FE2E;

    }

    ul li ul{

        display: none;

    }

    ul li:hover ul{

        display: block; /* display the dropdown */

    }

</style>

</head>

<body bgcolor="#E6E6FA">
<br>


<div>
    <div style="float: left; margin-left: 340px;>
    <a href="index.html"><img src="image/banner.png" alt="" align=""/></a>
</div>
<br><br><br><br><br><br>
<div style="float: left; margin-left: 1100px; margin-top: 0px;">
<a href="logout.php">Log out</a>
</div>
<br><br>



<!---------------------------row  begins------------------------->


<!------------------------------ibadan begins-------------------> 

<div style="height: 120px; float: left; margin-left: 375px; margin-top: 20px; width: 250px; border: 8px solid #58D3F7;">
<ul>
                <li>
                <a href="#">Ibadan Division</a>
                <ul>
                <li><a href="bm/ibadanbm1.php">BM Admin</a></li>
                <li><a href="sm/ibadansm1.php">SM/DAM/OM</a></li>
                </ul>
                </li>
                </ul>
</div>
<!-----------------------------ibadan ends-------------------------->


 <!------------------------------osun begins--------------------------> 

<div style="height: 120px; float: left; margin-left: 50px; margin-top: 20px; width: 250px; border: 8px solid #58D3F7;">
<ul>
                <li>
                <a href="#">Osun Division</a>
                <ul>
                <li><a href="bm/osunbm1.php">BM Admin</a></li>
                <li><a href="sm/osunsm1.php">SM/DAM/OM</a></li>
                </ul>
                </li>
                </ul>
</div>
<!------------------------------osun ends-------------------->
<br><br><br><br> 

<!--------------------row  ends------------------------------->

<br><br><br><br><br><br><br><br><br><br>
</body>

的login.php

<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost","alagbeco","a12345","alagbeco_modem");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("alagbeco_modem", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from user where password = md5('$password') AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: index2.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>

logout.php

<?php
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: index.php"); // Redirecting To Home Page
}
?>

session.php文件

<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost","alagbeco","a12345","alagbeco_modem");
// Selecting Database
$db = mysql_select_db("alagbeco_modem", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select username from user where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.php'); // Redirecting To Home Page
}
?>

2 个答案:

答案 0 :(得分:0)

我几乎可以肯定你的页面有错误,正如alfallouji写的那样。

mysql和mysqli不一样,我建议您也在本地服务器上安装mysqli。

不难做到,并节省了大量的调试时间。

参见php手册, http://php.net/manual/en/mysqli.installation.php

答案 1 :(得分:0)

您在进行连接时出错

试试:

<?php    
 $host='localhost';
 $user='alagbeco';
 $password='a12345';
 $db='alagbeco_modem';

 //If your PHP version is lower than 5.5
 $con = mysql_connect($host,$user,$password) or exit("Connection Error");
 $connection = mysql_select_db($db, $con);

 //If your PHP version is equal or higher than 5.5
 $connection =  mysqli_connect($host,$user,$password,$db);
?>