Title: header(&#8220;Location: $PHP_SELF&#8221;) problem
Last modified: August 18, 2016

---

# header(“Location: $PHP_SELF”) problem

 *  [Tyssen](https://wordpress.org/support/users/tyssen/)
 * (@tyssen)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/)
 * I’m using a script that enables users to set their own accesskeys but I’m getting
   a _Cannot modify header information – headers already sent by_ error which seems
   to be caused by _header(“Location: $PHP\_SELF”)_ in the script. Is there any 
   way around this?

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

 *  [Michael Bishop](https://wordpress.org/support/users/miklb/)
 * (@miklb)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/#post-363388)
 * This link for referencing headers already sent in WP. [FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem](http://codex.wordpress.org/FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem)
   
   You mention a script though, I’m assuming that’s outside of WP?
 *  Thread Starter [Tyssen](https://wordpress.org/support/users/tyssen/)
 * (@tyssen)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/#post-363403)
 * Yeah, I saw that, but it seems to refer to problems caused by WordPress files
   whereas mine, although it resides in my theme folder, is not a WP script. I don’t
   know much about how headers work in PHP so was wondering if there’s some kinda
   conflict.
 *  [prjg](https://wordpress.org/support/users/iiiiiiiv/)
 * (@iiiiiiiv)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/#post-363407)
 * Not really. Something (output) is being sent to the browser before the headers
   are being sent, and like that page suggested, it could be anything from white
   space to an errant tag.
 *  [forceagainstsomething](https://wordpress.org/support/users/forceagainstsomething/)
 * (@forceagainstsomething)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/#post-363408)
 * Tyssen,
    This is a common problem that people make when working with PHP’s header()
   function. In a nutshell what the error is telling you, is that you can not redirect
   because your PHP script has already sent HTML to the browser.
 *  The long explanation is this: When a browser request your script from the server,
   it sends the request in a header, like this:
 * GET /index.php HTTP/1.1
    Host: [http://www.yoursite.com](http://www.yoursite.com)
 *  And the server responds with something like this:
 * HTTP/1.1 200 OK
    Content-Type: text/html; charset=UTF-8
 *  Followed by the document’s HTML. Once the HTML has started flowing to the browser,*
   no more headers* can be sent. Now PHP’s header() function simply does this:
 * HTTP/1.1 302 OK
    Location: [http://www.myothersite.com](http://www.myothersite.com)
 *  When the browser gets this response, it redirects to the “location” URL instead.
   PHP’s header() function simply inserts “Location: [http://www.myothersite.com&#8221](http://www.myothersite.com&#8221);
   into the response header. But like I said above, once HTML has started flowing
   to the browser, you can’t send any more headers.
 *  Use of the header() function has to be before *anything* is output in your script.
   No text, no HTML, not even a single space.
 * – Sean
 *  Thread Starter [Tyssen](https://wordpress.org/support/users/tyssen/)
 * (@tyssen)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/#post-363560)
 * I wasn’t looking at the example properly which had the _header(“Location: $PHP\
   _SELF”)_ above the doctype. :/ So I tried splitting the script up with this in
   my header above the doctype:
 * `
    require_once("ak.class.php");
 * $arBindings = array("Home"=>array("/index.php", "1"),
    "Search Criteria"=>array("
   searchcriteria", "4"), "Quality Assurance"=>"/services.php", "Articles Archive"
   =>"/articles.php");
 * $objAK = new AccessKeys($arBindings);
 * if ($_POST)
    { if ($_POST["default"]) { $objAK->useDefaults(); header("Location:
   $PHP_SELF"); } else if ($objAK->setCookies()) header("Location: $PHP_SELF"); }
 * and the call that generates the output in my page, but I get a _Call to a member
   function displayOptions() on a non-object_ error message.
    Trying another script
   that does the same thing works fine if I create an example outside of WP, but
   if I try to do it within WP, I get _Invalid argument supplied for foreach()_.
   The foreach is working on an array set up inside an include inserted in the header
   above the doctype etc.

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

The topic ‘header(“Location: $PHP_SELF”) problem’ is closed to new replies.

 * 5 replies
 * 4 participants
 * Last reply from: [Tyssen](https://wordpress.org/support/users/tyssen/)
 * Last activity: [20 years, 2 months ago](https://wordpress.org/support/topic/headerlocation-php_self-problem/#post-363560)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
