Odd PHP header() behavior from POST to php_self - inconsistent across environments -


i'm having problem sending header(location:) response html form post php_self.

the essential parts of use case:

  • i'm including inside main page, page contains of form ui echoed out. form posts ($_server['php_self']).
  • this form contains "file" field , passes text (login, password, etc) ftp upload.
  • if upload successful, output header() location main page (along parameters tells containing page print successful upload message).
  • the main page (upon receiving header) should display include form echoed out again next upload.
  • everything works expected in dev, in prod, never form - it's header isn't getting sent.

the 3 things have made mysterious:

  • i have 2 environments, dev windows/apache 1.3.37/php 5.2.11 fast cgi, prod linux/apache (2.2.16)/php 5.2.14 fast cgi, , i've configured of relevant looking php params same across both dev , prod. in dev, aforementioned use case works great. in prod, file upload, it's though header not getting sent back. block included content should empty.
  • if separate include form content (the ui stuff) thing in include, , form posts separate file contains ftp upload logic, header sent @ completion of successful upload work in both dev , prod...the file uploads, header gets sent back, main page refreshes, , contents of include displayed.
  • in dev, through fiddler, can see post php_self form content, , see header returned back. in prod, can see post php_self, looks good, there never header returned returned back. however, in debugging, headers_sent told me header being sent right location. echo'ing headers_sent shows in main page.

extra trivia:

  • i thought @ first, .htaccess getting in way, again, works if split out ui , ftp upload stuff, , .htaccess in environment basic.
  • i thought, maybe output buffering change behavior - tried ob_start in variety of logical places, behavior never changed.
  • lastly, tried number options in header location - in cases, pointing http://www.google.com - still it's though no header being sent @ all.

i'm out of ideas - can offer direction on this??

here simplified test case - which, interestingly enough, behaves same in dev prod, @ least it's consistent now.

  • test.php included in page called "upload.php" couple of buttons rendered.
  • "try" posts php_self , rendered contents of test.php never come when header('location: ./upload.php') called...the space in including page blank.
  • however, "try2" posts test2.php calls header('location: ./upload.php') , re-renders buttons of included test.php page no problem.

here test.php:

<?php if($_post['submit']) { header('location: ./upload.php'); } else { echo '<form name="test" action="'.htmlentities($_server['php_self']).'" method="post"> <input type=submit value=try name=submit> </form> <form name="test2" action="test2.php" method="post"> <input type=submit value=try2 name=submit> </form>'; } ?> 

and here test.php...pretty simple.

<?php header('location: ./upload.php'); ?> 

and here snippet upload.php:

<!--    <div id="flashcontent"></div> --> </fieldset><?php require_once('test.php'); ?></div></div> </body> </html> 

today's update - in fact, behavior of simple test case not thought. including real-life file above simple test case include think resulting in classic headers-already-sent problem. once commented out real-life file, behavior of simple test case matches original case outlined @ start of post. so, simple test case loads header if called within include on form submit, , loads header if called page posted-to included file...no problem. however, in production, results of header call realized if called page posted-to, , not if called when posting php_self.

<div class="panel_wrapper"> <div id="general_panel" class="panel currentmod"> <fieldset> <legend><?php echo tb_uploadfiles; ?></legend> <?php //define('upload_opt',true); //require_once('upload_opt.php'); ?> <!--    <div id="flashcontent"></div> --> </fieldset><?php require_once('test.php'); ?></div></div> </body> </html> 

it header being sent after error. try turning errors off on production server.

also check no white space being output before header.

file names in linux case sensitive, make sure cases correct too. if can't find new location, trick (although doubt this, because google.com didn't work.)

try adding "exit()" after header declaration.

make sure header has correct syntax , absolute if resource external.

header("location: http://www.google.com"); exit(); 

try doing dumbed down example on production server test. remove post altogether , make sure header redirects working. restricted function if using shared host , aren't in control of php.ini file.

if none of work, snippet of header code interesting at.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -