Beginning PHP, not working

Hello all,
I am new to PHP so this might be a dumb question but i have been working on a simple menu and footer .php for a home, about, and help page. I feel as if it is all correct i have checked and double checked but i am still unable to have the .php file be included in the .html page. Every time i open the page neither the menu or the footer appear. I shall put the work that i have below:

menu.php

echo "Home - About - Help"; ?>

footer.php

<?php echo "

© " + new Date().getFullYear() + " First Website. All rights reserved.

"; ?>

home.html

Home Page
<?php include("menu.php"); ?>

Home Page

Some Text.

<?php include("footer.php"); ?>

about.html

About Page
<?php include("menu.php"); ?>

About Page

Some Text.

<?php include("footer.php"); ?>

help.html

News Page
<?php include("menu.php"); ?>

News Page

Some Text.

<?php include("footer.php"); ?>

Well, some servers don’t allow .html to execute PHP scripts, you’ll need to change them to .php. For example index.html to index.php.

P.S. Try to use code tags when listing scripts, for it is easier to read.

Also I find it easier to have a header.inc.php (that includes a navigational menu) and a footer (that includes my JQuery (Javascript)).

Here’s an example of what I’m talking about:
header.inc.php
[php]<?php
$phpSelf = filter_input(INPUT_SERVER, ‘PHP_SELF’, FILTER_SANITIZE_URL);
$path_parts = pathinfo($phpSelf);
$basename = $path_parts[‘basename’];
$filename = $path_parts[‘filename’];
$className = NULL;
$my_links = [
‘login.php’ => “Home”,
‘profile.php’ => “Profile”
];
function clearSession() {
unset($_SESSION[‘first_name’]);
unset($_SESSION[‘last_name’]);
unset($_SESSION[‘username’]);
unset($_SESSION[‘email’]);
}

clearSession();

$data = [];
$errMsg = [];
$spambotError = NULL;

$submit = filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_SPECIAL_CHARS);

if (isset($submit) && $submit === ‘login’) {
$data[‘username’] = filter_input(INPUT_POST, ‘username’, FILTER_SANITIZE_SPECIAL_CHARS); //Why wouldn’t we allow special chars in username and password
$data[‘password’] = filter_input(INPUT_POST, ‘password’, FILTER_SANITIZE_SPECIAL_CHARS); // In fact we want special chars in password to make it complex
$user = $login->read($data);
if ($user === TRUE) {
header(‘Location: index.php’);
exit();
}
}

$logout = filter_input(INPUT_GET, ‘logout’, FILTER_SANITIZE_SPECIAL_CHARS);

if (isset($logout) && $logout === ‘yes’) {
$login->delete();
}
?>
<!doctype html>

The Virtual Bar

The Virtual Bar

<?php echo ($user === FALSE) ? 'Username or Password is incorrect, please re-enter!' : NULL; ?>

  • Home
  • <?php echo (!$user) ? '
  • Register' . "\n" : NULL; ?> <?php echo ($user) ? '
  • Edit Profile
  • ' . "\n" : NULL; ?> <?php echo ($user) ? '
  • Logoff
  • ' . "\n" : NULL; ?>
<?php if ($user) { echo '

Welcome, ' . $user->username . '!' . "\n"; } else { ?> Username: Password:
  <?php } ?>
[/php] That way if I have to make any change to the menu (navigational) then I just have to change the header.inc.php file and not every page.

Not offering much here other then to say Correct!! I would rather put html in a php file that gives the flexibility to use either in the same file… so yes… use files with php extensions and not html.

Sponsor our Newsletter | Privacy Policy | Terms of Service