1

我的脚本有问题,我制作了一个登录脚本,您可以在其中输入用户名和密码,并且它在我的本地主机上完美运行(即我可以登录和退出访问管理面板)然后我将它上传到我的服务器上但是令人困惑的部分是,当我尝试使用正确的用户名和密码登录时,它没有访问管理面板并向我显示访问被拒绝消息,就像会话没有在服务器上设置,而它在我的本地主机上完美运行。 . 其次,我创建了一个新闻页面,我可以在其中查看新闻,它还显示没有帖子可显示,但在本地主机上一切正常,这是我的 home.php,我在其中输入用户名和密码

<?php

if(isset($_COOKIE['testsite'])){

    header('Location: enter.php');

}else{

echo"
<html>

<head>

</head>

<body>

<center>Please login...</center>


<div align='center'>
<form method='post' action='login.php' id='generalform'>
<table border='1' width='25%'>
<tr><td>Name: </td><td><input type='text' name='name' maxlength='15'/></td></tr><br />
<tr><td>Password: </td><td><input type='password' name='password' maxlength='15'/></td></tr><br />
<tr><td>Remember me?: </td><td><input type='checkbox' name='remember'/></td></tr><br />
</table>
<p>
<input type='submit' value='login' /><p>
</form>
<a href='index.htm'>Back To Main Page</a>
</div>

</body>

</html>";
}
?>

这是 enter.php 被访问的地方

<?php

session_start();

if(isset($_SESSION['name'])||isset($_COOKIE['testsite'])){

    include('session.php');

}else{

    echo "Access denied!";

}

?>

这是我的news.php,似乎没有从数据库访问 squery 我真的不知道出了什么问题,因为在 locahost 上它工作得很好

 <?php
include ('connect.php');
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";
$result = @mysql_query($query);

if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$url = 'comments.php?id='.$row['id'];
echo '<p><b>'.$row['title'].'</b><br />
'.$row['sd'].'<br />
Posted by : <b>'.$row['author'].'</b><br />
'.$row['post'].'<br />
<a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>';
}
} else {
echo 'There are no news posts to display';
}
?> 

这是 login.php

<?php
session_start();

if($_POST){

$_SESSION['name'] = $_POST['name'];
$_SESSION['password'] = md5($_POST['password']);


if($_SESSION['name'] && $_SESSION['password']){

    mysql_connect("localhost", "root", "nokiae71") or die("problem with connection...");
    mysql_select_db("testsite");

    $query = mysql_query("SELECT * FROM users WHERE name='".$_SESSION['name']."'");
    $numrows = mysql_num_rows($query);

    if($numrows != 0){

        while($row = mysql_fetch_assoc($query)){

            $dbname = $row['name'];
            $dbpassword = $row['password'];

        }
        if($_SESSION['name']==$dbname){
            if($_SESSION['password']==$dbpassword){

                if(($_POST['remember']) == 'on'){
                    $expire = time()+86400;
                    setcookie('testsite', $_POST['name'], $expire);
                }
                header("location:enter.php");

            }else{
                echo "Your password is incorrect!";
            }

        }else{
            echo "Your name is incorrect!";
        }

    }else{
        echo "This name is not registered!";    
    }

}else{
    echo "You have to type a name and password!";
}
}else{

echo "Access denied!";
exit;
}
?>

提前致谢

4

0 回答 0