2 Replies - 542 Views - Last Post: 05 January 2010 - 08:42 AM Rate Topic: -----

#1 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

System calls and headers

Posted 04 January 2010 - 04:03 PM

Hi everybody,
I've been trying to do this without success, and thus far I haven't been able to come up with a successful test case, so I'l try and explain this as clearly as possible.

I have an html page with is dynamically generated by a php script; the script is called using system, like this:
system( php myPage.php ); // l<- line 174



Later on, I replace that page with another using header, like this:
header( "Location: myPage2.html" );  // <- line 121



If you're wondering why the line numbers seem messed up, it's because these lines are called in methods; that doesn't really matter; what matters is that system is called first and header second.

The system call works fine, but then when it comes time for the header call, I get this error:
Warning: Cannot modify header information - headers already sent by (output started at example.php:174) in example.php on line 121



I've tried Googling this, and seen a lot of answers about whitespace, but I haven't been able to find a whitespace problem. So, I think this has something to do with how system() and header() interact, but I'm not sure. Can anyone enlighten me, please?

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: System calls and headers

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: System calls and headers

Posted 04 January 2010 - 04:54 PM

If you've output ANYTHING to the browser prior to that header call, you'll get that error, including whitespace, as you've found in your Googling. We're not going to be much help with two lines of code to go by. I don't think system is going to output anything to your browser, so you're probably barking up the wrong tree.
Was This Post Helpful? 0
  • +
  • -

#3 Zel2008   User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Re: System calls and headers

Posted 05 January 2010 - 08:42 AM

Thanks Jack,
That was actually very helpful, I didn't realize header() was that picky. I do have one more question, though--since this doesn't work, how do you flush the output buffer from a system call? I managed to come up with a test case by doing things differently:

<?php

ob_start();
system( "ls ." );
$html = ob_get_contents();
ob_end_clean();
echo $html;

// flush somewhere here														 

echo "blah";

?>



What this does isn't exactly what I want, if I put it in a web browser it does the ls, but then outputs "blah" right underneath the ls. What I want it to do is output the ls, clear the page, and then echo "blah". (And yes, I know "ls" is a really bad thing to do, but this is just for the test case. :)) Does that make sense?

Thanks,
Zel2008
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1