【发布时间】:2016-10-02 21:51:09
【问题描述】:
当我运行 wp_signon () 时,我有几个类似这样的警告: “警告:无法修改标头信息 - 标头已由 /web/ 中的(输出开始于 /web/htdocs/www.example.com/home/wp-includes/class.wp-styles.php:237)发送htdocs/www.mysite.com/home/wp-includes/pluggable.php 第 892 行" 无论如何它都会登录,如果我改变页面那么不会给我带来任何问题,但我无法理解这些错误。 我附上登录代码。 非常感谢您的帮助!
header.php:
<div id="loginbar">
<?php $current_user = wp_get_current_user();
if(isset($_POST["submit"])){
custom_login();
}?>
<?php if(!is_user_logged_in()): ?>
<form name="frontlog" method="post">
<input id= "log" type="text" name="log" placeholder="Username">
<input id= "pwd" type="password" name="pwd" placeholder="Password">
<input type= "submit" name="submit" class="linkbuttonleft" id="loginbutton">
</form>
<a class="linkbuttonright" title="Registrati" href="http://www.example.com/registrazione/">
<img id="chiave" src="http://www.example.com/wp-content/themes/BiscuitsTheme/immagini/chiave.png" onmousedown="return false"></a>
<?php else: ?>
<p> <?php echo 'Benvenuto ' . $current_user->user_login;?> </p>
<a class="linkbuttonleft" title="Logout" href="<?php echo wp_logout_url( home_url() ); ?>"></a>
<img id="lucchetto" src="http://www.example.com/wp-content/themes/BiscuitsTheme/immagini/lucchetto.png" onmousedown="return false"></a>
<a class="linkbuttonright" title="Profilo" href="http://www.example.com/profilo/">
<img id="profilo" src="http://www.example.com/wp-content/themes/BiscuitsTheme/immagini/profilo.png" onmousedown="return false"></a>
<?php endif; ?>
</div>
functions.php:
function custom_login() {
$creds = array();
$creds = array(
'user_login' => $_POST["log"],
'user_password' => $_POST["pwd"],
'remember' => true
);
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
}
else {
wp_set_current_user( $user->ID, $user->name );
wp_set_auth_cookie( $user->ID, true, false );
}
};add_action( 'after_setup_theme', 'custom_login' );
【问题讨论】:
-
这意味着服务器已经发送了标头信息,因此您在某处有不同的标头或回显功能,然后尝试重定向 - 登录后。检查上述错误消息中的文件 n 行号。
标签: php wordpress login header