Php 脚本在服务器上不工作,但在本地主机上工作正常

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

我的脚本有一个问题,我制作了一个登录脚本,您可以在其中输入用户名和密码,它在我的本地主机上运行良好(即我可以登录和退出并访问管理面板)然后我将其上传到我的服务器上,但令人困惑的是,当我尝试使用正确的用户名和密码登录时,它没有访问管理面板,并向我显示拒绝访问消息,就好像会话没有在服务器上设置,而在我的本地主机上却工作正常。。其次,我创建了一个新闻页面,在那里我可以查看新闻,这也表明没有帖子可以显示,但是在本地主机上,一切都很正常 这是我的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>";
}
?>
这是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;
}
?>

如果您访问,您可以检查会话文件是否正确crated@Mihai我刚刚添加了它你还在尝试从服务器版本连接到本地主机吗?没有,我正在尝试在服务器上使用它我在线上传了它,但当它在线时我无法访问你更新了服务器上的数据库吗?通常我会忘记这一部分,在小项目上。
 <?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';
}
?> 
<?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;
}
?>