我有一个 header.php 和一个 home.php。
我正在尝试将标题和描述从我的 home.php 传递到 header.php。问题出在我的 header.php 中,在 dom 中:没有看到我的 php 变量,或者 php 仅在我的 html 头部无法工作,而它在正文中工作正常。
有什么建议么?
这是我的文件:Header.php:
<?php session_start();
header('Content-type: text/html; charset=utf-8');
function sendPageInfo($title, $desc){
if($title)
$pageTitle= $title;
if($desc)
$description = $desc;
echo $pageTitle;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $pageTitle; ?></title> //the $pageTitle won't show up!!!
<meta charset="UTF-8">
<meta name ="description" content=" <?php echo $description; ?> "> //$description won't show
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/menu.css"/>
<link rel="stylesheet" type="text/css" href="css/pages.css" />
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="css/lightbox.css" rel="stylesheet" />
</head>
<body>
<section class="bodyWrap">
<?php echo $pageTitle; ?> //// PAGE TITLE DOES SHOW UP!!!!!!!!!!!
<section class="headerNav">
<div class="logo">
</div>
<nav class="tpMenu shdw">
<ul>
<li><a href="home.php">Home</a></li>
<li><a class="events" href="events.php">Events</a></li>
<li><a class="press" href="pressNotes.php">Press</a></li>
<li><a class="media" href="eventsalbum.php">Media</a></li>
<li><a class="about" href="about.php">Our Vision</a></li>
<li><a class="contact" href="contact.php">Contact Us</a></li>
<!--This is where you add memeber.php if the user is signed in-->
<?php
if(!isset($_SESSION['username']))
{
echo "<li><a href=\"MemberLogin.php\"> Login</a></li>";
}
?>
<?php
if(isset($_SESSION['username']))
{
echo "Welcome! ";
echo $_SESSION['username'];
echo " ";
echo "<li><a href=\"logout.php\">Log out</a></li>";
}
?>
</li>
</ul>
</nav>
</section>
主页.php:
<?php include_once("includes/header.php");
sendPageInfo('Troy Telugu Association Home', 'A Nonprofit organization fouced on South Indian culture in Troy, Michigan');
?>
<?php include_once("addHomeContentAlbum.php");?>
<?php include_once("includes/footer.php");?>