PHP with XHTML MP 1.2 - php

I have the following code: index.php
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN"
"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta content="metadesc" name="description" />
<meta content="metakey" name="keywords" />
<meta name ="googlebot" content="index,follow" />
<meta name="robots" content="INDEX, FOLLOW" />
<link rel="stylesheet" href="core.css"/>
</head>
<body>
<div class="page">
<div class="head">
<div class="menu">
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
</div>
</div>
</div>
</body>
</html>
my only issue is that when i try and preview the document, nothing shows no source code, no error or anything.
I have tried with the following in the header before any content to try and rectify the issue as i have looked and mobile xhtml can't be served as text/html. I have tried the following (obveously not at the same time):
<?php header("Content-type: application/xml ");?>
<?php header("Content-type: application/xhtml+xml ");?>
<?php header('Content-type: application/vnd.wap.xhtml+xml'); ?>
Still no output/errors or anything. Anyone any advise on what the issue could be?

Well it turned out display errors was off and i was getting a http 500 error in php as short tags wasn't turned off and it was trying to parse the <? in the xml

Related

Using PHP "include" function adds a second header to page

I've just updated my site to use the PHP "include" function to add a CSS menu to every page. When I look at the result of the include function online, it has added a second HTML and Head to each page. The web site and menu work perfectly but this looks like bad design to me.
My CSS code is in an HTML file called menu.html. I've tried to remove the HTML and Head code from the menu.html file hoping to avoid the second instance in the final result but it doesn't work. The menu doesn't display correctly.
Is this a problem or should I do something else to eliminate the second insertion of the HTML and Head?
Here is partial code from a file using the "include" function to call the menu:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD>
<META NAME="Description" CONTENT="Gary and Nancy's travel photo gallery">
<META NAME="Keywords" CONTENT="Gary and Nancy's travel photo gallery">
<META http-equiv="title" CONTENT="Gary and Nancy's travel photo gallery">
<META NAME="revisit-after" CONTENT="30 days">
<META NAME="classification" CONTENT="travel">
<META NAME="robots" CONTENT="all">
<META NAME="distribution" CONTENT="global">
<META NAME="products" CONTENT="Travel Photos">
<TITLE>Gary and Nancy's Photo Gallery</TITLE>
<link Rel=Stylesheet href="style.css" type="text/css">
</HEAD>
<font class=a24b color="#937666">Gary and Nancy's Photo Gallery</font>
<br><br>
<div class="menu">
<?php include 'menu.html';?>
</div>
<br>
Here is partial code of the menu.html file:
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="mbcsmbmcp.css" type="text/css" />
</head>
<body>
<div id="mbmcpebul_wrapper" style="max-width: 804px;">
<ul id="mbmcpebul_table" class="mbmcpebul_menulist css_menu">
<li class="first_button"><div class="buttonbg gradient_button gradient38" style="width: 62px;">Home</div></li>
<li><div class="buttonbg gradient_button gradient38" style="width: 94px;"><div class="arrow"><a>Australia</a></div></div>
<ul class="gradient_menu gradient116">
<li class="gradient_menuitem gradient29 first_item">Cairns</li>
<li class="gradient_menuitem gradient29">Heron Island</li>
<li class="gradient_menuitem gradient29">Port Douglas</li>
<li class="gradient_menuitem gradient29 last_item">Great Barrier Reef</li>
</ul></li>
Here is the resulting code that I see online i.e. including double HTML and HEAD:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD>
<META NAME="Description" CONTENT="Gary and Nancy's travel photo gallery">
<META NAME="Keywords" CONTENT="Gary and Nancy's travel photo gallery">
<META http-equiv="title" CONTENT="Gary and Nancy's travel photo gallery">
<META NAME="revisit-after" CONTENT="30 days">
<META NAME="classification" CONTENT="travel">
<META NAME="robots" CONTENT="all">
<META NAME="distribution" CONTENT="global">
<META NAME="products" CONTENT="Travel Photos">
<TITLE>Gary and Nancy's Photo Gallery</TITLE>
<link Rel=Stylesheet href="style.css" type="text/css">
</HEAD>
<Body>
<center>
<font class=a24b color="#937666">Gary and Nancy's Photo Gallery</font>
<br><br>
<div class="menu">
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="mbcsmbmcp.css" type="text/css" />
</head>
<body>
<div id="mbmcpebul_wrapper" style="max-width: 804px;">
<ul id="mbmcpebul_table" class="mbmcpebul_menulist css_menu">
<li class="first_button"><div class="buttonbg gradient_button gradient38" style="width: 62px;">Home</div></li>
<li><div class="buttonbg gradient_button gradient38" style="width: 94px;"><div class="arrow"><a>Australia</a></div></div>
<ul class="gradient_menu gradient116">
<li class="gradient_menuitem gradient29 first_item">Cairns</li>
<li class="gradient_menuitem gradient29">Heron Island</li>
<li class="gradient_menuitem gradient29">Port Douglas</li>
<li class="gradient_menuitem gradient29 last_item">Great Barrier Reef</li>
</ul></li>
"this looks like bad design to me"
...yep. You should not have a HTML document inside another one. Get rid of the inner one.
Menu.html should contain the HTML specific to the menu, and nothing else. Then you can slot it into the body of your main document using include(). You probably need to keep the stylesheet link, too
Get rid of all the header information on menu.html, just keep this line below (put it in the header of the main file)
<link rel="stylesheet" href="mbcsmbmcp.css" type="text/css" />

PHP session id is not constant on localhost (xampp, ubuntu)

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?

Page reapets it self when using include

So Lately i was working on a website on LocalHost Using XAMPP Application.
So i created header.php with the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="A short description." />
<meta name="keywords" content="put, keywords, here" />
<title>Website Name</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="menu">
<a class="item" href="index.php">Home</a>
<a class="item" href="../forum/">Forums</a>
<a class="item" href="live-chat.php">Live Chat</a>
<a class="item" href="Login.php">Log In</a>
<a class="item" href="Register.php">Register Now!</a>
<div id="userbar">
<?php
error_reporting(E_ALL & ~E_NOTICE);
include 'search.php';
if($_SESSION['signed_in'])
{
echo 'Welcome <b>' . htmlentities($_SESSION['user_name']) . '</b>. Not you? <a class="item" href="logout.php">Log out</a>';
}
?>
</div>
</div>
<div id="content">
And a Login.php with this code ( Here is the 4 lines of it ) :
<?php
include 'connect.php';
include 'header.php';
etc..... php code....
Ok so the problem is When i try to open the login.php in web browser i got the code in header.php duplication many many times like it don't end duplicating it self and if i open the source code of login.php i will got unlimited number of the code used in header.php like all the source code is header.php repeatedly.
So I'am asking you guys for help on how to fix this and what is the error ??
NOTE: Sorry if their was a thread duplication but i didn't know on what to search exactly.
If you want anymore information I'am ready.
Thanks all much appreciated
Use
include_once('header.php');
everywhere instead. It will check to see if the file has already been included.
use require_once instead, it will load the file just once, and only if needed.
You have more info here

How to properly include a header file in a webpage

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"); ?>

How to insert content in a header of web page from other file?

I have a problem with an included header in a phtml file.
I have an MVC project and the view file is builded like this
<?php
require_once'header.phtml';
//SOME PHP COMMAND TO PRINT SOME STUFF
reuire_once 'footer.phtml';
?>
When I press F12 in Google Chrome the header content apears in the body of the page, like this :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style type="text/css"></style></head>
<body>
<title>UserList</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../css/Mystyle.css">
<meta name="description" content="MVC MiniShop Project">
<meta name="keywords" content="MVC Online Store">
<meta name="author" content="Vasile Vetisan">
<meta charset="UTF-8">
<div class="menu">
<ul>
<li>Home</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
<br style="clear:left">
</div>USER LIST IS:<br> <table border="1"><tbody><tr><td>USER_ID</td><td>FIRST_NAME</td><td>LAST_NAME</td><td>USERNAME</td><td>EMAIL</td><td>PASSWORD</td></tr><tr><td>2</td><td>Test</td><td>Unu</td><td>test1</td><td>test1#gmail.com</td></td></tr></tbody></table>
</body></html>
Even if I change the structure of the ViewUser page like this:
<html>
<header>
<?php
require_once 'header.phtml'
?>
</header>
<body>
//SOME GENERATED STUFF WITH PHP
</body>
</html>
The result is the same as previous :( .
So as summary of my post I need a method to insert content in header of a phtml page from another page using php or phphtml extenxions.
I have tried a lot of stuff so I need some new ideas or answers.
I think the very good, easy and effective way of including parts is using php, where part.html is file with your code.
<?php
include "part.html";
?>
Example:
part.html
<p> Hello world! </p>
index.php
<body>
<?php
include "part.html";
?>
</body>
output should be
<body>
<p> Hello World! </p>
</body>

Categories