gpt4 book ai didi

php - 脚本中出现多个 PHP "header(url)", "Cannot modify header information"错误

转载 作者:行者123 更新时间:2023-11-29 08:05:21 24 4
gpt4 key购买 nike

嘿,我有一些脚本,如果满足某些条件,则应该更改页面的 url,如果不满足,则应该更改其他位置。

我收到此错误:

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25c/b1401/ipg.website/process.php:7) in /hermes/bosweb25c/b1401/ipg.website/process.php on line 53

这是我的 PHP。我很确定它与 if 语句有关,但在我上传到我的网络主机之前,它在我的 WAMP 服务器上运行良好。

<?php
session_start();
$con = mysql_connect('website', 'members_db_admin', 'password');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';

// make members the current db
$db_selected = mysql_select_db('members_db', $con);
if (!$db_selected) {
die ('Can\'t use members database : ' . mysql_error());
}
$hash_password = md5($_POST['password']);

$email = $_POST['email'];

$result = mysql_query("SELECT email,password FROM `members` WHERE email = '$email'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();

}

$row = mysql_fetch_row($result);

if ($row[0] != $email && $hash_password != $row[1])
{
$query = "INSERT INTO members (email, password)
VALUES('".$_POST['email']."','".$hash_password."')";

// Perform Query
$result2 = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result2) {
$message = 'Invalid query: ' . mysql_error() . "\n";
//$message .= 'Whole query: ' . $query;
die($message);
}
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$hash_password;
$_SESSION['loggedin']="YES";
$url = "Location: /welcome.php";
header($url);
}
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$hash_password;
$url = "Location: /checklogin.php";
header($url);
?>

最佳答案

您的问题是echo 'Connected successfully<br />'; 。在使用 header() 设置标题之前,您无法打印任何内容。称呼。确保您没有任何 echo在您的header()之前调用.

关于php - 脚本中出现多个 PHP "header(url)", "Cannot modify header information"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22839884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com