Another PHP include issue - php

I've gone through the archives and read a bunch of questions relating to why PHP include won't work. I've tried to fix my problem using answers to the other questions, but am still having issues.
This is my code:
<!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>Fuel Status Map</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div id="map">
<?
require 'MapLink.php';
?></div>
<div id="title"><img src="title.png" width="400" height="200" />
</div>
<div id="links">
<img src="FuelStatusLink.png" width="400" />
<br />
<img src="NWSofficeLink.png" width="400" />
<br />
<img src="FuelSpecialistLink.png" width="400" />
<br />
<img src="AdminLink.png" width="400" />
<br />
</div>
<div id="legend"><img src="Legend1.png" width="400">
</div>
<div id="logos">
<img src="PSlogo.png" width="140" height="150" />
<img src="GBlogo.png" width="250" height="150"/>
</div>
</div>
</body>
</html>
The page is supposed to look like this: http://www.directdocuments.com/GACC/GBSite/predictive/FuelStatus/FuelStatusMap.php
but looks like this: http://gacc.nifc.gov/gbcc/predictive/FuelStatus/FuelStatusMap.php
The MapLink.php is in the same directory, and works correctly. I'd post the link to that as well, but I can't post any more links.

It looks like you don't have short open tags enabled in your PHP configuration, so the require line is being output literally (use View Source to see this). Use the full tag.
<?php
require 'MapLink.php';
?>
From the documentation:
PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).
See also Are PHP short tags acceptable to use?

Related

preg_match not giving output

i am trying to filter data using preg_match it seems to be correct and matching on view source code but when i run the code it gives no match found
here is my pattern
/\<p\>(.*)\<center\>/
string is
<!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>Untitled Document</title>
</head>
<body>
<small>Photo courtesy of hortongrou </small>
</div>
<p>I have developed theasional thriller.<br />
<code> </code><br />
<li><strong>Beginning Ubuntu Linux<img style="border:none !important; margin:0px !important;" src="" border="0" alt="" width="1" height="1" />, by Keir Thomas and Jaime Sicam.</strong> For those who like to transition from Windows to Linux, install Ubuntu Linux on one of yoto you.</li>
</ol>
<p class="alert">For more Linux books that I recommend, browse <a rel="nofollow" href="http://astore.amazon.com/thgest-20">The Geek Stuff bookstore at Amazon.</a></p>
<p>There are several hundreds of books on Linux. <strong>What is your favorite Linux book that is not on this list?</strong><br />
<code> </code><br />
<em>If you like this article, please bookmark it on <strong>delicious and Stumble it</strong>.</em></p>
<center>
<div style="margin-left:2px; margin-top:10px; margin-bottom:10px; ">
<!-- AD BLOCK -->
</body>
By default . doesn’t match new lines. Try adding DOTALL (s) modifier like this /<p>(.*)<center>/s.

JavaScript menu behaving strangely in Chrome

I have a dropdown javascript menu on a site that gets included into each page by some php. There's no problem in Firefox, but when viewed in Chrome, the menu acts strangely on most of the pages, but not all, and I can't figure out what's going correctly on the few proper pages.
The homepage looks fine in either one: http://solve-et-coagula.us/
Like this page, most (in Chrome) add a space above the menu: http://solve-et-coagula.us/design.php
This page displays correctly: /rabbithole/k_2.php
This one does not: /hermeticism/gunas.php
Also, in all cases in Chrome, the dropdowns appear from the top of the menu images instead of the bottom.
I've been using the menu for a while, having grabbed the format somewhere years ago and adapting it aesthetically.
The pages start off like (k_2.php):
<?php
session_name("MyLogin");
session_start();
include($_SERVER['DOCUMENT_ROOT']."/menu.html");
?>
<!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" dir="ltr">
<head>
<title>Registration</title>
<meta content="text/html" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="rabbithole.css" />
<link rel="stylesheet" type="text/css" href="/general.css" />
<script src="/javascript.js" type="text/javascript"></script>
<script src="rabbithole.js" type="text/javascript"></script>
</head>
<body>
<table border="0" cellspacing="20" width="100%">
<tr>
<td class="title"><h1>Create an Account</h1></td>
</tr>
[...]
Here's the graphic design page
<?php
session_name("MyLogin");
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" dir="ltr">
<head>
<title>Graphic & Web Design</title>
<meta content="text/html" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="rabbithole/rabbithole.css" />
<link rel="stylesheet" type="text/css" href="general.css" />
<script src="javascript.js" type="text/javascript"></script>
</head>
<body>
<?php
include($_SERVER['DOCUMENT_ROOT']."/menu.html");
?>
<table border="0" cellspacing="20" width="100%">
<tr>
<td class="title"><h1>Graphic & Web Design</h1></td>
</tr>
<tr>
<td>
<p>
[...]
here's the full menu.html file
<div align="center" id="page">
<div id="header">
<div id="mainmenu">
<span onmouseover="dropdownmenu(this, event, menu1, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Hermetic Qabalah" class="menuimages" src="/images/libri.png" /></span>
<span onmouseover="dropdownmenu(this, event, menu2, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Eastern Mysticism" class="menuimages" src="/images/theology.png" /></span>
<span onmouseover="dropdownmenu(this, event, menu3, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Ceremonial Magick" class="menuimages" src="/images/rituals.png" /></span>
<span onmouseover="dropdownmenu(this, event, menu4, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Solve et Coagula" class="menuimages" src="/images/solveetcoagula.png" /></span>
<span onmouseover="dropdownmenu(this, event, menu5, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Liber Legis" class="menuimages" src="/images/thelema.png" /></span>
<span onmouseover="dropdownmenu(this, event, menu6, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Lemegeton" class="menuimages" src="/images/lemegeton.png" /></span>
<span onmouseover="dropdownmenu(this, event, menu7, '146px')" onclick="return clickreturnvalue()" onmouseout="delayhidemenu()"><img alt="Miscellanea" class="menuimages" src="/images/hermeticism.png" /></span>
</div>
</div>
</div>
An help would be appreciated; this has not been solved.
On http://solve-et-coagula.us/design.php there is extra " " at the top (not present on other pages), when its removed then the menu is displayed properly.
Take a look into the code of that page, and see if anything extra is being echoed by PHP.
Also, You should have the meta link and title tag inside the head element.

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

getting image with php and displaying in html

i know it is so simple problem but eventually it isn't working and i am a newbie. in the index.html, a swf sends an image and displayImage.php(below code) should display it on another page. why isn't it working??
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$no=0;
while (file_exists("images/$no.jpg"))
$no++;
header('Content-Type: image/jpeg');
$image = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents("images/".$no.".jpg", $image);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-9" />
<title>Your Image</title>
<link href= "style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo"></div>
<div id="body"></div>
/////////display image//////////
<img src="images/<?$no.".jpg?>">
</body>
</html>
You don't echo the filename (and you have a quoting error, but this could be a typo):
<img src="images/<?php echo $no ?>.jpg" />
Assuming that storing the file actually works.
<img src="images/<?=$no.".jpg"?>">
This might be the issue. The line below the "display image" comment, should probably read:
<img src="images/<?= $no ?>.jpg">
Could be that you're using XHTML strict. IMG tags can't be unclosed like in normal HTML. You have to end it with a /> instead. (it's supposed to fail catastrophically when you make an error but it only does that when you send the right MIME type header to treat it as XML, so treated as text you may get unpredictable results.....). If it's printing the name of the file (like images/1.jpg) then you know that it's parsing the inline PHP correctly....
i deleted the line "header('Content-Type: image/jpeg');" and it works!

Categories