标题('位置:http://google.com');不工作

时间:2014-12-10 10:29:52

标签: php wordpress header

header('Location: http://google.com');

无法正常显示错误消息

  

警告:无法修改标头信息 - 已在/ home / crdemo / public_html / codehelp中发送的标头(输出从/home/crdemo/public_html/codehelp/wp-content/themes/codehelp/header.php:2开始)第55行/wp-content/themes/codehelp/page.php

<form action="" method="post">
          Select the category : <select name="categoryid"><option value="2">wordpress</option><option value="3">php</option><option value="4">css</option></select>
          <input class="help" type="text" name="title" />
          <h1 class="title">Discription</h1>
          <textarea class="help" type="text" name="discription"></textarea>
          <h1 class="title">Code</h1>
          <textarea class="help" name="code" ></textarea>

          <input class="post" type="submit" value="submit"  />
          </form>

          <?php
          if($_SERVER['REQUEST_METHOD'] == 'POST') {

          $catname = array ($_POST['categoryid']);



          $title = $_POST['title'];

          $discription = $_POST['discription'];

          $code = $_POST['code'];

          // Create post object
          $my_post = array(
            'post_title'    => $title,
            'post_content'  => $code,
            'post_excerpt'   => $discription,
            'post_status'   => 'publish',
            'post_author'   => 1,
            'post_category' => $catname
          );

          // Insert the post into the database
          wp_insert_post( $my_post );
          ?><?php

         header('Location: http://google.com');

          exit();
          }
?>

1 个答案:

答案 0 :(得分:0)

将html发送到客户端后,无法使用header()函数。你必须把你的PHP代码放在html之前。