繁体   English   中英

脚本无法在服务器上运行,但在本地主机上可以正常运行

[英]script not working on the server but works fine on the localhost

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

提前致谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM