I need some help.
I’ve got some php code which I want on every page of my site. But if I want to edit something in it ill have to edit every section of code ,in that php code, on every page. Is there a way so I can only edit on file and it reflects on all of the others on the other pages.
Here is the php code:
<?php
if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
echo '<gen id= mess>You need to login to use this!!!</gen>';
echo "<p><a href=\"login.php\">login</a></p>";
}else{
// Member only content
// ...
// ...
// ...
// Display Member information
echo "<p>User ID: " . $_SESSION["valid_id"];
echo "<p>Username: " . $_SESSION["valid_user"];
// Display logout link
echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
}
?>
P.S: i was thinking that is may work (but it didnt):
include 'filename';
or
require 'filename';
You can use require_once or include_once functions depending on your requirements:
These are likely to be most appropriate to what you want to do, because you only want a header once.
However, if you wanted to include something more than once, you can use:
This is not restricted to simply including parts of pages that you wish to include – You can also use these functions to include files that contain functions that you wish to make use of in other parts of your code.