I am confused with two terms
header (\"Location:homepage_php\");
include(\"homepage.php\");
I am g
The header function is used to send raw HTTP headers back to the client: PHP header function
<?php
header("HTTP/1.0 404 Not Found");
?>
The above (taken from the PHP documentation) sends a 404 header back to the client.
The include function is used to include files into the current PHP script (the same as require) PHP include function
vars.php
<?php
$color = 'green';
$fruit = 'apple';
?>
test.php
<?php
echo "A $color $fruit"; // A
include 'vars.php';
echo "A $color $fruit"; // A green apple
?>
This example (again from the PHP documentation) includes the vars.php script in the test.php script and, after the include, allows the test.php script to access the variables declared in the vars.php script.
NOTE:
the header location will eb a location that is readable by the web browser... and not the directory structure. (which include does)
also the include method will not change the page that the browser is pointing at.
1 tells PHP to send a Location header to the HTTP client, forcing a redirect to "homepage.php".
2 tells PHP to include "homepage.php" inline to execution of the current page.
As a note about your question, your confusion might be over the term "header". It is overloaded sometimes to refer to the top part of a page in reference to code separation. Code separation is a common practice where one puts PHP code/HTML used in multiple pages into a separate file, and then included in the top (header) of each page.
HTH,
-aj
The first tells the browser to send a header to the browser to redirect to "homepage_php" (should be .?)
The second includes the file at the top. This is useful if you're using methods or classes stored in other files, or want the same content to appear on multiple pages.
Header redirects the browser. Include tells php to include the contents of a file and execute it as PHP.
the main difference in include and header is that the include
does not change the url but header
does. That means header
sends you (redirects you) to that page but include
fetch the page for you.
see this example:
this is from test.php which is including file from test2.php
this is from test1.php using header so it redirects me to test2.php