Title: PHP header problem
Last modified: August 20, 2016

---

# PHP header problem

 *  Resolved [fourninjadeveloper](https://wordpress.org/support/users/fourninjadeveloper/)
 * (@fourninjadeveloper)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/)
 * `header('Location: somesite.php?num=0');`
 * I’ve been working on a custom WordPress Plugin for months. And I finally thought
   I was done until this problem hit me. This part of the plugin works in the background
   so I will need to send data dynamically to a PHP page. However the header command
   is not working, I’ve been trying to figure this out for a couple weeks and I’ve
   gotten no where. Am I missing something or do I need to go another route?

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387213)
 * Have you tried it with wp_redirect():
    [http://codex.wordpress.org/Function_Reference/wp_redirect](http://codex.wordpress.org/Function_Reference/wp_redirect)
 *  Thread Starter [fourninjadeveloper](https://wordpress.org/support/users/fourninjadeveloper/)
 * (@fourninjadeveloper)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387215)
 * Yes and it didn’t work. I have the page using file_put_contents in a log so if
   the data is being sent the php page. However when I take the link out the code
   and paste into the web browser; it works fine.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387321)
 * Without seeing the full code there is not much we can do to troubleshoot.
 * Make sure you don’t output anything before the redirect.
 *  Thread Starter [fourninjadeveloper](https://wordpress.org/support/users/fourninjadeveloper/)
 * (@fourninjadeveloper)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387366)
 * Do you think file_put_contents command is causing an issue?
 *  Thread Starter [fourninjadeveloper](https://wordpress.org/support/users/fourninjadeveloper/)
 * (@fourninjadeveloper)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387396)
 *     ```
       function check($data)
       {
   
       /* function checks parser and than parse the information and send it to the actions folder. */
   
       $pattern = '|X-Original-To: (.*)|i';
       /* retrieving sql statement */
       $test = checkparsers();
       $flag = 0;
       $par = "";
       $parse ="";
       $i = 0;
       /*Database connection*/
       /*Checking Database for match*/
   
         preg_match_all($pattern, $data, $out, PREG_PATTERN_ORDER);
   
            $matches = explode(': ',$out[0][0]);
       while($result = mysql_fetch_array($res))
       {
   
            if($matches[1] == $result[$i])
              {
               /*set flag to one*/
               $flag = 1;
   
               /*Database connecting take out*/
   
                while($result2 = mysql_fetch_array($res)){
                /*building array to pass to parsing function*/
   
                $type = $result2[4];
                  $src = $result2[5];
   
                  if($src == 'body')
                  {
                      /*This should split the entrie email into two parts*/
                      $split = preg_split("Content-Transfer-Encoding:", $data);
   
                      $parse = $split[1];
   
                  }
   
                  /*This gets the header information*/
                  if($src == 'email')
                  {
                      $split = preg_split("Content-Transfer-Encoding: 7bit", $data);
   
                      $parse = $split[0];
                  }
   
                  if($src != 'email' && $src != 'body')
                  {
                      $parse = $data;
                  }
   
               if($type == 'beforeafter')
               {
                   $par = 'beafter';
                  $parse = beafter($parse, $result2);
               }
               if($type == 'reg')
               {
                   $par = 'regexpress';
                   $parse = regexpress($parse, $result2);
               }
           if($type == 'fnot')
               {
                   $par = 'fnot';
                   $parse = fnot($parse, $result2);
               }
           if($type == 'cal')
               {
                   $par = 'calculate';
                   $parse = calculate($parse, $result2);
               }
   
               }
           /*Database connection taken out*/
   
                /*looping through the files. */
       /* This is a test*/
                       header('Location: somesite.php?num=0');
   
               }
               $i = $i + 1;
   
           }
   
           /*psssing information to to the action files*/
   
           /*Handling action files*/
             file_put_contents("/home/amuser1/public_html/1funnel.com/public/wp-content/plugins/Paser/actions/actionlog.txt","functions.php passed\n" , FILE_APPEND);
   
       };
       ```
   
 * Here is the function. I took out the database connection for security purposes.
 *  Thread Starter [fourninjadeveloper](https://wordpress.org/support/users/fourninjadeveloper/)
 * (@fourninjadeveloper)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387468)
 * I solved the issue.
 * Apparently when using the header command it requires a browser and since I need
   this to happen in the background the header command will not work. After some
   researching and trial and error I came across another way of using the [file_put_contents](http://php.net/manual/en/function.file-get-contents.php).
   It’s hard for me to explain it thoroughly but some example code and solution 
   can location [here](http://stackoverflow.com/questions/7352832/get-request-from-php-using-file-get-contents-with-parameters).

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

The topic ‘PHP header problem’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 6 replies
 * 2 participants
 * Last reply from: [fourninjadeveloper](https://wordpress.org/support/users/fourninjadeveloper/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/php-header-problem/#post-3387468)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
