Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使删除了空白,PHP标头也无法在MAMP中工作_Php_Mysql_Redirect_Header_Mamp - Fatal编程技术网

即使删除了空白,PHP标头也无法在MAMP中工作

即使删除了空白,PHP标头也无法在MAMP中工作,php,mysql,redirect,header,mamp,Php,Mysql,Redirect,Header,Mamp,我正在使用MAMP,由于某些原因,我没有在php中使用header重定向,如果有什么错误,有人能看一下下面的代码吗 我读过类似的文章,发现这是由标题标签前的空白引起的,但在我的例子中不是 请给出你的建议…谢谢 <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="DBase"; // Data

我正在使用MAMP,由于某些原因,我没有在php中使用header重定向,如果有什么错误,有人能看一下下面的代码吗

我读过类似的文章,发现这是由标题标签前的空白引起的,但在我的例子中不是

请给出你的建议…谢谢

<?php

$host="localhost"; // Host name 

$username="root"; // Mysql username 

$password="root"; // Mysql password 

$db_name="DBase"; // Database name 

$tbl_name="customers"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from the form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

$myusername = stripslashes($myusername);
$mypassword = md5($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword"); 
header("location:/Account/index.php");
}
else {
echo "Wrong Username or Password.";
}
?>

应该是这样的:

header('Location: http://example.com/Account/index.php');
exit;

应该是这样的:

header('Location: http://example.com/Account/index.php');
exit;
这是一种方法,但您可以使用输出缓冲来解决此问题,在发送之前,所有输出到浏览器的开销都在服务器中缓冲。您可以通过在脚本中调用
ob\u start()
ob\u end\u flush()
或在php.ini或服务器配置文件中设置output\u buffering configuration指令

编辑和追加解决方案:----------->

您可以将输出缓冲用作

    <?php
    ob_start();
    $host="localhost"; // Host name 

$username="root"; // Mysql username 

$password="root"; // Mysql password 

$db_name="DBase"; // Database name 

$tbl_name="customers"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from the form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

$myusername = stripslashes($myusername);
$mypassword = md5($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword"); 
header("location:/Account/index.php");
}
else {
echo "Wrong Username or Password.";
}
    ob_end_flush();
    ?>

这是一种方法,但您可以使用输出缓冲来解决此问题,在发送之前,所有输出到浏览器的开销都在服务器中缓冲。您可以通过在脚本中调用
ob\u start()
ob\u end\u flush()
或在php.ini或服务器配置文件中设置output\u buffering configuration指令

编辑和追加解决方案:----------->

您可以将输出缓冲用作

    <?php
    ob_start();
    $host="localhost"; // Host name 

$username="root"; // Mysql username 

$password="root"; // Mysql password 

$db_name="DBase"; // Database name 

$tbl_name="customers"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from the form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

$myusername = stripslashes($myusername);
$mypassword = md5($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword"); 
header("location:/Account/index.php");
}
else {
echo "Wrong Username or Password.";
}
    ob_end_flush();
    ?>

我在MAMP中遇到了同样的问题,结果是在我的php.ini配置文件中禁用了输出缓冲。我所要做的就是把它打开

在php.ini中找到以下行:

output_buffering = Off
并将其更改为:

output_buffering = 4096
然后重新启动MAMP

有关更多详细信息,请参阅此帖子:

我在MAMP中遇到了同样的问题,结果是在我的php.ini配置文件中禁用了输出缓冲。我所要做的就是把它打开

在php.ini中找到以下行:

output_buffering = Off
并将其更改为:

output_buffering = 4096
然后重新启动MAMP

有关更多详细信息,请参阅此帖子:

是的,大多数浏览器试图修复无效的
位置
标题,就像修复无效的HTML一样。谢谢Vicario,但我使用的是本地服务器“MAMP”。是的,大多数浏览器试图修复无效的
位置
标题,就像修复无效的HTML一样。谢谢Vicario,但我使用的是本地服务器“MAMP”.在我的脚本中,是否可以给出一个例子,在哪里确切地使用上述函数???这是一个很棒的@Ziinloader-that ob_start();函数是我需要与MAMP兼容的东西。干得好!感谢您的详细解释-这真的很有帮助。在我的脚本案例中,是否可以给出一个例子,在哪里确切地使用上述函数???这是伟大的@Ziinloader-这是ob_start();函数是我需要与MAMP兼容的东西。干得好!谢谢你的详细解释,这真的很有帮助。