Jump to content

var_dump...browser output


jimfog
 Share

Recommended Posts

When you use var_dump to output the content of a variable into the browser is this still considered output in the sense that an echo statement is?

Link to comment
Share on other sites

yes both are same. browser does not know It is generate by var_dump() or echo or print_r() if anything is sent and printed it will be considered as output

Link to comment
Share on other sites

Ok...I understood that. But what about the head section of a page. I am talking about the tags inside <head></head>. I am asking this cause I am facing a strange case. Normally I should get an error but I do not-take a look at this code:

include 'header.html'; 	  if(isset($_POST['submit'])&&(!empty($_POST['remember'])))			 {					 $username = $_POST['username'];					 $passwd = $_POST['password'];					 if ((login($username, $passwd))) {						 setcookie_pers($username);						  header("Location: adminmember.php");					 }				 }

If the user fills in the login form and ticks the remember me option a cookie a cookie is set(this is what the function setcookie_pers does). Everything happens though after the head section which is included above by using include. How happens and I do not get any errors? The header.html file contains the title page plus all the tags contained in <head></head> I finally got an error(the usual "output started...headers already sent"), although I do not understand why this was not happening from the beginning. Very weird...no error again.

Edited by jimfog
Link to comment
Share on other sites

From PHP's point of view, "output" is "HTTP content", i.e. anything that is sent to the client that is not an "HTTP header". Cookies are sent as headers.PHP may be configured to delay sending "output" until execution of the PHP file is finished (the so called "output buffering"). In that case, within the PHP file, it may look "as if" you're first writing output and then send headers, but in reality, PHP is still always sending headers first and content afterwards. If you use this "feature", the user won't see anything until the PHP file is finished, so your file better be fast.

Link to comment
Share on other sites

One small question...So, as I understand, the head section of a page(<head>...and whatever tags are contained in it) are not considered HTTP headers Am I right?

Link to comment
Share on other sites

no, they would be considered HTTP headers. when dealing without output from PHP script, any kind of output, whitespace, BOM, etc is considered output to the browser. It has no idea of what generated the output, other than output was generated.

Link to comment
Share on other sites

The phrase below is taken from the PHP manual-on the section about the setcookie() function: This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. According to the above the head section is considered output-at least that is what I understand-correct me if I am wrong.

Link to comment
Share on other sites

Anything that you can see in the source code sent to the browser is output. All HTML and text, and anything that isn't PHP logic.
So I am right to say that <head> is considered output.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...