So I have a header file:
<html>
<head>
<link href="/design_header.css" rel="stylesheet" type="text/css" />
</head>
<body>
content
</body>
</html>
And I want to place this header in my file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
meta tags etc.
</head>
<body>
<div id="container_big">
<?php include 'header_login.php'; ?>
content
</div>
</body>
</html>
The problem is now I have regular <html>, <head>, <body> tags inside the <body> tag of my webpage. In the html validator I receive errors like
Stray start tag html.
Stray end tag head.
An body start tag seen but an element of th
e same type was already open.
How to do it properly? Btw. I also place a footer to the bottom of the webpage the same way.
Your header file should only contain the HTML text you want for the header.
As it will be inserted into another webpage, it should not be a full HTML document.
Having only HTML for Header in Header
One option is to instead include in your header file only the HTML that is for the header (used by all pages that include it). However this has the downside that your not following the recommendation to have CSS loading before is rendered.
See: https://stackoverflow.com/a/1642259/1688441
Header File
<link href="/design_header.css" rel="stylesheet" type="text/css" />
content
Other files
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
meta tags etc.
</head>
<body>
<div id="container_big">
<?php include 'header_login.php'; ?>
content
</div>
</body>
</html>
Having only HTML for Header in HeaderFile and Separate HeadFile
You could have have a separate global_head_include.html (or txt, php, etc) file and put your CSS code there.
Header File (for include)
Header content
File with CSS includes (for include)
<link href="/design_header.css" rel="stylesheet" type="text/css" />
Whatever else is global...
Other files
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
meta tags etc.
<?php include 'global_head_include.php'; ?>
</head>
<body>
<div id="container_big">
<?php include 'header_login.php'; ?>
content
</div>
</body>
</html>
This is how I set out my headers and footers in my current PHP site:
header.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>James Wright - Young Software Developer</title>
<link rel="stylesheet" href="style.css" />
<meta name="description" content="The online home of a young web designer and software developer." />
<link rel="icon" type="image/png" href="/img/ico.png" />
</head>
<body>
<div id="holder">
<div id="menu"></div>
<div id="mainContent">
footer.php:
</div>
<div id="mainReflect"></div>
<p class="footer">© James Wright <?php echo date("Y"); ?>. Minimum resolution: 1024x768 <a href="http://validator.w3.org/check?uri=referer" target="_blank"><img
src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" style="vertical-align: middle;"/></a>
<a href='http://www.powermapper.com/products/sortsite/'><img src='http://www.powermapper.com/images/badge-v1/sortsite-badge-small-5.png' width="80" height="15" alt='Broken link checker and accessibility checker top 5% - SortSite' style='vertical-align: middle;'/></a>
</p>
</div>
</body>
</html>
Then whenever I create a new page, all I need to do is this:
<?php include("header.php"); ?>
<p>Main body content!</p>
<?php include("footer.php"); ?>
Related
First I had this:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<title>PHP file</title>
</head>
<body>
<h1>
<?php
echo "Hi again...";
?>
</h1>
</body>
</html>
I accessed the file through localhost/learningphp/myfirstfile.php and it rendered properly, showing me a h1 element with the text "Hi again...".
Then I changed to this:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<title>PHP file</title>
</head>
<body>
<p>
<?php
echo "Hi again...";
$myName = "Sahand";
echo $myName;
?>
</p>
</body>
</html>
Notice the change of <h1> tags to <p> tags, and the addition of myName. Still, when I go to localhost/learningphp/myfirstfile.php myName (Sahand) is not added to the page, and "Hi again..." is still shown in "h1 styling", like when I viewed the first version of the php file. Why is this and what can I do about it?
You will have two issues in this case may be
You are saving the file somewhere else or you didn't save the
updated content.
Your Browser history try a hard refresh by using Ctrl+F5 (for windows) Keys
together
My head content(metas, scripts etc.) appears in the body tag. I have header php with this code
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device=width">
<title<?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<header class="header">
<h1 id="logo">|||</h1>
<h4 id='title' ><?php the_title(); ?></h4>
</header>
<body>
and footer.php is closing it with this. `
<?php wp_footer(); ?>
</body>
</html>`
Already tried changing encoding from UTF-8 to UTF-8 without BOM using Notepad++, and still the same ,, this is my website if you wanna see with inspect [website]
website . Any ideas ? :S
Your html is broken:
<title> Name Lastname / Official Website</title>
^---- missing >
I had a problem that I was struggling with a couple days ago, and the problem lies in my session id handling while using localhost (xampp local server).
What I now tried to do, is to create two separate pages, the first one randomizes a session id in such a way:
<?php
session_start();
$random_number = rand();
$_SESSION['random_number'] = $random_number;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8"/>
<link rel="stylesheet" href="style.css" />
<title>Understanding PHP sessions...Page 1</title>
</head>
<body>
<div id="contentarea">
<div id="innercontentarea">
<h2>Understanding PHP sessions...Page 1</h2>
<p>Random number generated
<span style="font-weight:bold;">
<?php echo $_SESSION['random_number']; ?>
</span>
</p>
<p>PHP session id
<span style="text-decoration:underline;">
<?php echo session_id(); ?>
</span>
</p>
Go to next page
</div>
</div>
</body>
</html>
So, this creates a random session number here, and should output the same number on the second page basic_session2, which basically the same, but the difference is in session initialization, which is only:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8"/>
<link rel="stylesheet" href="style.css" />
<title>Understanding PHP sessions...Page 2</title>
</head>
<body>
<div id="contentarea">
<div id="innercontentarea">
<h2>Understanding PHP sessions...Page 2</h2>
<p>My Favorite movie is
<span style="font-weight:bold;">
<?php echo $_SESSION['random_number']; ?>
</span>
</p>
<p>PHP session id
<span style="text-decoration:underline;">
<?php echo session_id(); ?>
</span>
</p>
</div>
</div>
</body>
</html>
But it echoes out a different random number! So, now, I am guessing there is a problem with my session cookie path, as this session number is not holding up.
The system I use is Ubuntu, and the localhost directory for xampp is a standard one. Do you know how to solve that issue, or maybe encountered such a problem?
The index.php file in the html document root of a web server contains:
<?php
header("Location: http://www.sitename.com/0");
exit();
?>
...
(see below for full listing but I think nothing gets done b/c the exit())
There is no file or directory in the document root named "0"
Can anyone tell me what it's doing / why it would be used?
When I enter http:/www.sitename.com/ in my browser address bar, the site loads and the address bar displays:
www.sitename.com/0
if I click on a button, a new page loads and the address bar displays something like:
www.sitename.com/0/index.php?toDo=sometext
and it I type in a file name that doesn't exist like this:
www.sitename.com/0/file_not_there.php
it doesn't complain, it just goes too the main page (and leaves www.sitename.com/0/file_not_there.php displaying in the address bar).
Any assistance you can give in helping me understand what's going on is appreciated.
full listing of public_html/index.php:
<?php
header("Location: http://www.sitename.com/0");
exit();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Site Name</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
-->
</style>
</head>
<body>
<div align="center">
<p> </p>
<p><img src="/somedir/images/logo.png" /></p>
<p class="style1"><strong>Welcome</strong><br />
</p>
</div>
</body>
</html>
I currently am trying to use print inside of the JQuery footer by writing it is not working. Instead nothing shows up. In the earlier php page I stored it into the session using...
session_start();
$_SESSION['username'] = $_POST['username'];
my code in my html page is as follows...
<?php session.start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Food For Thought</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="header" id = "hdrMain" name = "hdrMain" data-nobackbtn = "true">
<h1>Food for Thought</h1>
</div><!-- /header -->
<div data-role="content" align ="center">
Play
Profile
Logout
</div><!-- /content -->
<div data-role="footer">
<p>Logged in as: <?php print $_SESSION["username"]; ?> </p>
</div>
</div>
</body>
</html>
Thank you any help is appreciated.
Edit: Problem was that the file I was trying to run php code ended in .html instead of .php. Thank you all who tried to help.
Well, you're HTML page has:
session.start();
it should be
session_start();