テスト サーバーでサイトを構築しましたが、現在、サイトをホストする新しいサーバーにサイトを配置しています。接続に PDO を使用しており、準備されたステートメントが実行されると、Web サイトのホームページにリダイレクトされますが、サイトが別のサーバーにあるため、このエラーが発生します
エラー
Cannot modify header information - headers already sent by (output started at /home1/mlayzell/public_html/alpha/cms/includes/my-db-functions.php:17)
それ自体がメンバーシップのアクティベーション用のコードであり、ユーザーがサインアップして確認メールをユーザーに送信し、リンクをクリックすると、アカウントがアクティブに変更されます。誰かがこれを理解するのを手伝ってくれるなら、これが私のコードです。
MY-DB-FUNCTION.PHP
<?php
require("config.php");
function connect_to_db() {
global $dbhost, $dbname, $dbuser, $dbpass, $db;
try {
$db = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.'', $dbuser, $dbpass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $error) {
echo 'ERROR: ' . $error->getMessage();
}
}
?>
PHP
if($_GET['action']==0) {
if(isset($_POST['name'],$_POST['email'],$_POST['password'])) {
$key = md5(rand(0,1000));
$date = date('Y-m-d H:i:s');
$statement_user = $db->prepare("INSERT INTO `app_users` ( `use_name`, `use_key`, `use_email`, `use_password`, `use_date`, `use_status`, `use_typ_id`) VALUES (:use_name, :use_key, :use_email, :use_password, :use_date, :use_status, :use_type);");
$statement_user->execute(array(':use_name' => $_POST['name'], ':use_key' => $key, ':use_email' => $_POST['email'], ':use_password' => $_POST['password'], ':use_date' => $date, ':use_status' => "0", ':use_type' => "0"));
$to = $_POST['email'];
$subject = 'Signup | Verification';
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by clicking the link below.
------------------------
Email: '.$email.'
Password: '.$password.'
------------------------
Please click this link to activate your account:
http://theapplist.com/alpha/cms/users/handler-users.php?action=5&use_email='.$_POST['email'].'&use_key='.$key.'
';
$headers = 'From:noreply@mysite.com' . "\r\n";
mail($to, $subject, $message, $headers);
header('location:../index.php?signup=success');
}
else {
echo "FAIL";
}
}