这个问题已经在这里有了答案:
警告:无法修改标头信息-错误已发送的标头[重复](4个答案)
3年前关闭。
我正在使用WordPress的自定义登录页面, 但是有问题。单击提交按钮后, 出现以下错误:
警告:无法修改标头信息-已在C:\ wamp \ www \中发送过标头(输出从C:\ wamp \ www \ wordpress-4.7.3 \ wp-includes \ class.wp-styles.php:237开始)第904行的wordpress-4.7.3 \ wp-includes \ pluggable.php警告:无法修改标头信息-已发送的标头(输出从C:\ wamp \ www \ wordpress-4.7.3 \ wp-includes \ class开始。第905行的C:\ wamp \ www \ wordpress-4.7.3 \ wp-includes \ pluggable.php中的wp-styles.php:237)警告:无法修改标头信息-已发送的标头(输出从C:\开始第906行的C:\ wamp \ www \ wordpress-4.7.3 \ wp-includes \ pluggable.php中的wamp \ www \ wordpress-4.7.3 \ wp-includes \ class.wp-styles.php:237)警告:无法修改标头信息-已发送的标头(输出从C:\ wamp \ www \ wordpress-中的C:\ wamp \ www \ wordpress-4.7.3 \ wp-includes \ class.wp-styles.php:237开始)第1195行的4.7.3 \ wp-includes \ pluggable.php
这是我的自定义登录完整代码
<?php
function dlf_form() {
echo '
<form class="form-inline" method="post" action="' . $_SERVER['REQUEST_URI'] . '">
<div class="form-group">
<input type="text" id="email" name="login_name" placeholder="إسم المستخدم">
</div>
<div class="form-group">
<input type="password" id="pwd" name="login_password" placeholder="كلمة السر">
</div>
<button type="submit" name="dlf_submit">تسجيل</button>
</form>
';
}
function dlf_auth( $username, $password ) {
global $user;
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
}
if ( !is_wp_error($user) ) {
wp_redirect(home_url('wp-admin'));
}
}
function dlf_process() {
if (isset($_POST['dlf_submit'])) {
dlf_auth($_POST['login_name'], $_POST['login_password']);
echo 'Test text';
}
dlf_form();
}
function dlf_shortcode() {
ob_start();
dlf_process();
return ob_get_clean();
}
add_shortcode('dm_login_form', 'dlf_shortcode');
#1
在wp_redirect(home_url(‘wp-admin’))之后;放一个wp_die();
评论前必须登录!
注册