Title: problem redirecting from header.php
Last modified: August 18, 2016

---

# problem redirecting from header.php

 *  [darylastbury](https://wordpress.org/support/users/darylastbury/)
 * (@darylastbury)
 * [19 years ago](https://wordpress.org/support/topic/problem-redirecting-from-headerphp/)
 * Hello all,
    Im trying to inclue an additional php code to the header page that
   will allow a page redirect on a button click,
 * Into the header page in including the follwoing:
 * [CODE]
    <? if($_POST[‘submitmain1_x’]>0 || $_POST[‘submitmain1_y’]>0){
 *  header(“Location: [http://www.google.co.uk&#8221](http://www.google.co.uk&#8221););
 *  exit();
    } ?> [/CODE]
 * AND
 * [CODE]
    <form method=post action=<?php echo $_SERVER[‘PHP_SELF’]; ?> name=”myform”
   id=”myform”> <input type=image src=”./../images/signin.jpg” alt=’start search’
   name=”submitmain1″ id=”submitmain1″ style=”margin-left:160px; margin-top:5px”
   > </form> [/CODE]
 * Therefore, when the button is clicked, I would like to be able to redirect to
   google.co.uk.
 * However, im getting the follwoing error:
    “Warning: Cannot modify header information–
   headers already sent by (output started at D:\best-mobile-contracts.co.uk\wwwroot\
   blog\wp-content\themes\default\header.php:3)”
 *  Any id3eas where im going wrong/ Am I inseting the php rediret code into the
   wrong php file (header.php)?
 * Cheers for any help

Viewing 1 replies (of 1 total)

 *  [cheesemasterdan](https://wordpress.org/support/users/cheesemasterdan/)
 * (@cheesemasterdan)
 * [19 years ago](https://wordpress.org/support/topic/problem-redirecting-from-headerphp/#post-571418)
 * The header command has to be the very first thing sent to the browser… If any
   output has already been sent then a header will have gone with it…
    I can’t remember
   if anything is sent to the browser prior to the header.php file, but I don’t 
   think it is (I’ll check later – at work at the moment) but one thing to make 
   sure is that you don’t have any white space before the header command in your
   script…

Viewing 1 replies (of 1 total)

The topic ‘problem redirecting from header.php’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [cheesemasterdan](https://wordpress.org/support/users/cheesemasterdan/)
 * Last activity: [19 years ago](https://wordpress.org/support/topic/problem-redirecting-from-headerphp/#post-571418)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
