Title: CHALLENGE: fix our php code please!
Last modified: August 19, 2016

---

# CHALLENGE: fix our php code please!

 *  [lowwa](https://wordpress.org/support/users/lowwa/)
 * (@lowwa)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/challenge-fix-our-php-code-please/)
 * A few versions of WordPress ago, our custom search code was working fine:
 *     ```
       <form method="post">
       <input type="text" class="searchbox" name="apple">
       <input type="submit" class="searchbox_submit" name="orange">
       </form>
       <?php
       if (isset($_POST['orange']) && !empty($_POST['apple'])){
       $term = str_replace(" ", "+", trim(strip_tags($_POST['apple'])));
       header('Location: http://example.com/tag/'.$term);
       }
       ?>
       ```
   
 * …but now it is no longer working. When a user submits a search query, the infamous“
   headers” WordPress error pops up like this:
 * `Warning: Cannot modify header information - headers already sent by (output 
   started at /home/example/public_html/wp-content/themes/example/header.php:4) 
   in /home/example/public_html/wp-content/themes/example/header.php on line 58`
 * Now, some of you will reply and say “check for spaces and line breaks in your
   php code i.e. wp-config.php and other files” but I promise you, this is not the
   problem. We have tried inserting this code on a fresh WordPress install with 
   the twentyten default theme, and this error still displays whenever you try to
   search something.
 * Something must have changed in the recent WP releases, but I don’t know what,
   to make this custom search query not work correctly.
 * For the record, in the above error, “line 58” is where that custom code appears
   in the template, and “line 4” is usually just the opening html tag or body tag
   it seems.
 * To clarify, we are trying to make our WordPress site turn queries into this “
   results” format:
 * `example.com/tag/keyword+keyword/`
 * If anyone has any ideas why this is no longer working, or perhaps can suggest
   alternative coding to make this work, I would be very grateful.
 * Cheers all.
 * P.S. please note: This was previously working even with mod_security enabled 
   on our server, and without using any special WP plugins that allow certain PHP
   code to execute properly… our server was using CGI as a PHP handler and is now
   using FCGI, for what’s its worth…

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [lowwa](https://wordpress.org/support/users/lowwa/)
 * (@lowwa)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/challenge-fix-our-php-code-please/#post-1906606)
 * NOBODY has excepted our challenge!? lol please guys.
 *  Thread Starter [lowwa](https://wordpress.org/support/users/lowwa/)
 * (@lowwa)
 * [15 years ago](https://wordpress.org/support/topic/challenge-fix-our-php-code-please/#post-1906815)
 * Anyone?
 *  [CyberAlien](https://wordpress.org/support/users/cyberalien/)
 * (@cyberalien)
 * [15 years ago](https://wordpress.org/support/topic/challenge-fix-our-php-code-please/#post-1906816)
 * Of course error is being displayed, you are trying to send a header after echoing
   html code. Ether move your code above your html form or instead of `header('Location:
   http://example.com/tag/'.$term);`
    use `echo '<script type="text/javascript">
   document.location.href = "http://example.com/tag/', urlencode($term), '"; </script
   >';`
 *  Thread Starter [lowwa](https://wordpress.org/support/users/lowwa/)
 * (@lowwa)
 * [15 years ago](https://wordpress.org/support/topic/challenge-fix-our-php-code-please/#post-1906818)
 * Cool thanks Vjach, I will try that and post back soon!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘CHALLENGE: fix our php code please!’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [headers](https://wordpress.org/support/topic-tag/headers/)
 * [output](https://wordpress.org/support/topic-tag/output/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)

 * 4 replies
 * 2 participants
 * Last reply from: [lowwa](https://wordpress.org/support/users/lowwa/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/challenge-fix-our-php-code-please/#post-1906818)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
