一段时间以来,我一直在努力解决这个错误。
我已经创建了一个个人资料站点,如果我在本地运行它,登录并重定向到个人资料页面没有问题。
但是很快我上传了它,当我按下登录时没有任何反应。我只是得到一个空页面......但是如果我打开页面源,我可以看到它正在读取我的 init.inc.php 文件。但只是阅读了评论代码。而且由于我不会收到任何错误消息,所以我真的不知道问题出在哪里。
aaa 希望你明白我想说的:)
这是我的登录页面
<?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>
还有我的 init.inc.php 文件
<?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'];
所以它与会话有关,是否有另一种方法来编写代码以使其工作?