PHP登录无法工作,并且不会显示任何错误

PHP登录无法工作,并且不会显示任何错误,php,sql,Php,Sql,我已经为这个错误挣扎了一段时间了 我已经创建了一个配置文件站点,如果我在本地运行它,那么登录并重定向到配置文件页面是没有问题的 但很快我上传了它,当我按下登录时,什么也没有发生。我只是得到一个空页。。。但是如果我打开页面源代码,我可以确定它正在读取我的init.inc.php文件。但是只读取注释代码。。 由于我不会收到任何错误信息,我真的不知道是什么问题 希望你明白我想说的:) 这是我的登录页面 <?php include 'core/inc/init.inc.php'; if ($

我已经为这个错误挣扎了一段时间了

我已经创建了一个配置文件站点,如果我在本地运行它,那么登录并重定向到配置文件页面是没有问题的

但很快我上传了它,当我按下登录时,什么也没有发生。我只是得到一个空页。。。但是如果我打开页面源代码,我可以确定它正在读取我的init.inc.php文件。但是只读取注释代码。。 由于我不会收到任何错误信息,我真的不知道是什么问题

希望你明白我想说的:)

这是我的登录页面

<?php 
 include 'core/inc/init.inc.php';
 if ($_SERVER['HTTP_HOST'] != 'localhost') // running in remote server
    $server = 'pixeltouch2.mysql.domeneshop.no';  
    else // running locally
    $server = 'pixeltouch2.mysql.domeneshop.no';

mysql_connect($server, "LOGIN", "pass") or die(mysql_error());
  mysql_select_db("pixeltouch2") or die(mysql_error()) ;


$errors = array();

if (isset($_POST['username'], $_POST['password'])){
    if(empty($_POST['username'])){
        $errors[] = 'The username cannot be empty.';    
    }
        if(empty($_POST['password'])){
        $errors[] = 'The password cannot be empty.';
    }
//Log in
    if (valid_credentials($_POST['username'], $_POST['password']) == false ){
        $errors[] = 'Username / Password incorrect.';
    }
        if (empty($errors)){
            $_SESSION['username'] = htmlentities($_POST['username']);
            $_SESSION['uid'] = fetch_user_id($_SESSION['username']);

            header("Location: profile.php?uid=" . $_SESSION['uid']);
                die();
                echo $_SESSION['uid'];
        }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Pixeltouch</title> 

<link rel="stylesheet" type="text/css" href="ext/style.css" />

</head> 
<body> 
<div id="page-wrap"> 
<div id="main-content"> 
<br/>
<?php include_once('template/head.inc.php');
?>
<div id="menu"> 

<?php include_once('template/nav.inc.php');
?> 

</div> 
<!-- SKRIVBOX-->

<div>
<?php 
if(empty($errors) == false){
?>
<ul>

<?php

foreach ($errors as $error) {
    echo "<li>$error</li>";
}

?>
</ul>

<?php

}else{
echo 'Need an account ? <a href="register.php">Register here</a>'; 
}

?>



</div>
<br/>
<form method="post" action="" >
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo  htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password"  id="password" />
</p>
<p>
<input type="submit" value="Login" />
</p>

</form>


<!-- SKRIVBOX END-->
</div> 

<?php include_once('template/foot.inc.php');
?>
</div>
</body>
</html>

这是关于会话的问题,是否有其他方法来编写代码使其工作?

错误就在这里。您已经在向浏览器发送输出,如果说“输出”,则表示发送到浏览器的内容不是http头

因此,请在您的文件中查找:

  • 在标题位置语句之前回显/打印语句
  • ++++++++++
    +++++++++++
    
    您确定已将其上载到php服务器吗?:)请在所有文件的开头使用
    错误报告(E\u all)
    ini\u集(“显示错误”,1)
    显示错误为什么在两个PHP文件中重复mysql\u连接?为什么登录名和密码不同???另外:请不要把真实的登录/通行证信息放在这里!对于localhost和public server,您的两个服务器变量都声明为“pixeltuch2.mysql.domeneshop.no”。连接详细信息正确吗?我建议你重新上传所有内容,以确保所有内容(更新)都已上传。与你最近的评论相同-你的服务器日志说什么???如果您没有向PHP页面报告错误,当然您将“在PHP页面上看不到错误”。看看你的服务器日志!你好谢谢实际上,我通过删除session_start()解决了这个问题;从init文件,然后添加到我的网站顶部和底部的flush,我不知道这样做是否正确,但我可以。感谢您提供的代码示例,如果您删除init.inc.php中的
    session\u start
    ,则
    设置($\u session['username'))
    的计算结果将始终为false。如果您已经在使用输出缓冲,那么就没有必要删除
    会话\u start
    code您是对的,我将其放回原处,现在连接到sertain用户的sql开始工作:)嘿!如果答案有用,别忘了把问题标为已解决。
         <?php
         session_start();
    
    /*
         mysql_connect("pixeltouch2.mysql.domeneshop.no", "LOGIN", "PASS") or die(mysql_error()) ; 
         mysql_select_db("pixeltouch2") or die(mysql_error()) ;
         */
    
         if($_SERVER['HTTP_HOST'] != 'pixeltouch2.mysql.domeneshop.no')// running in remote server
            $server = 'pixeltouch2.mysql.domeneshop.no';  
            else // running locally
            $server = 'pixeltouch2.mysql.domeneshop.no';
    
        mysql_connect($server, "login", "pass") or die(mysql_error());
          mysql_select_db("pixeltouch2") or die(mysql_error()) ;
    
         $path = dirname(__FILE__);
         include("{$path}/user.inc.php");
    
         ?>
    
    
                                            <!--Registration/Login (START)-->
         <?php 
    
    
         $exceptions = array('register', 'login', 'user_list', 'profile', 'edit_profile', 'upload');
    
         $page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4);
    
         if(in_array($page, $exceptions) == false){
            if (isset($_SESSION['username']) == false){
            header('Location: login.php');
            die();
            }
          }
         ?>
    
                                            <!--Registration/Login (END)--> 
    
    
                                                <!--User Profile (START)-->
         <?php
         $_SESSION['uid'] = 1;
    
    
         ?>
    
                                                <!--User Profile (END)-->
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/3/p/pixeltouch/www/book/core/inc/init.inc.php:2) in /home/3/p/pixeltouch/www/book/login.php on line 32
    
    When I look @ line 32 I its my  header("Location: profile.php?uid=" . $_SESSION['uid']);
                    die();
                    echo $_SESSION['uid'];
    
    ++++<?php
          session_start();
    
    <?php
      session_start();
    // No spaces at the beginning
    
     // You close the php tag
     ?>++++++++++
     ++++<!--Registration/Login (START)-->+++++++
     <?php 
     $exceptions = array('register', 'login', 'user_list', 'profile', 'edit_profile', 'upload');