PHP脚本不工作
问题描述:
我有以下脚本:PHP脚本不工作
<?php
//session_start();
include('config.php');
$username=$_POST['username'];
$password=$_POST['password'];
if($_SERVER['REQUEST_METHOD'] == "POST") {
$result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
if(mysql_num_rows($result) > 0) {
$_SESSION['is_logged_in'] = 1;
}
}
if(!isset($_SESSION['is_logged_in'])) {
// display your login here
echo "it worked";
header("location:account.php");
} else {
header("location:http://mysite.com/index.php");
}
?>
,它输出的页面说,从字面上这一点;
0) { $_SESSION['is_logged_in'] = 1; } } if(!isset($_SESSION['is_logged_in'])) { // display your login here header("location:account.php"); } else { header("location:http://mysite.com/index.php"); } ?>
我不明白。 没有错过任何报价或类似的东西。 它用于工作,直到我创建的文件的.htaccess和php.ini中
config.php文件(数据库连接):
<?php
$link = mysql_connect('localhost', 'DB_user', 'DB_pass');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('DB', $link);
?>
它的工作是肯定的。
站点开始给出错误500 - 我在一个教程后使用Google搜索并创建了其他两个文件。
的php.ini:
php_flag register_globals off
register_globals = 0
memory_limit = 64M
的.htaccess:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
我只是复制粘贴其他网站此内容。
答
查看网站的原始输出(查看源代码)。很可能整个PHP文件都是按照原样输出的,根本不会被PHP解释。浏览器试图将<
和>
之间的部分解释为HTML标签,因此它们消失。
最可能的原因是AddHandler x-mapp-php5 .php
,因为您的服务器上没有配置名为x-mapp-php5
的处理程序,或者处理程序配置错误。
答
它看起来像认为“>”是HTML标记的末尾。在你的代码中看不到任何明显的东西。 config.php的外观如何?
这些文件中有什么 - “config.php”,“.htaccess”和“php.ini” - 你为什么创建它们?你写了什么? – 2012-03-07 07:26:14
你是如何“运行”这个文件的? – deceze 2012-03-07 07:26:36
是.php文件还是.html文件?你使用什么网络服务器? – DdD 2012-03-07 07:27:20