473,417 Members | 1,414 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Dynamic Content - Meta Tags

I have some simple dynamic content pages (included below). I need to
know how to add specific meta tags (ie. description, keywords, ect.),
as well as extra specific header coding to a page. I would like to
have these on the Links page. Is this possible? and how?
------------------------------------------------------------------------------------------------------------------------------
index.php
---------------
<?php
// Assign the requested page to a shorter variable for simplicity.
// The value of $_GET["page"] will be obtained from index.php?
page=RIGHT_HERE
$p = $_GET["page"];
// Check for bad requests. This is necessary to prevent the wrong
files
// from being included. This is a security measure.
if (strpos($p,"..")) {
// A bad request has been made, exit immediately. Do not proceed
// with the inclusion.
// strpos($p,"..") checks for presence of ".." in the page
request.
// ".." can be used to access files in parent directories
die("Bad page request");
}
// File to include.
// this will be something like '/www/page.php'. If $p is empty, fall
back
// main.php. THIS FILE MUST EXIST, otherwise bad things will happen.
if (!$p) $p = "main";
$content_file=$_SERVER["DOCUMENT_ROOT"]."/".$p.".php";
// See if $content_file exists. If it does not, redirect to the
homepage.
if (!file_exists($content_file)) {
header("Location: {$_SERVER["PHP_SELF"]}");
exit();
}
// At this point everything is fine. Set the appropriate title and
then
// include the files.
// Syntax: $variable = (condition) ? value_if_true : value_if_false;
$title = ($p) ? "$p - My Site!" : "Main page - My Site!";
include("header.php");
include($content_file);
include("footer.php");
?>

---------------------------------------------------------------------------------------------
header.php
----------------
<html>
<head>
<title><?=$title ?></title>
<style type="text/css">
<!--
body {
background-color: white;
color: #333333;
font-family: verdana;
font-size: 11px;
}
-->
</style>
--------------------------------------------------------------------------------------------
links.php
------------
[meta description]
[extra javascript special for this page]
<p>
This is my links page. Notice there is no header or footer inclusion
in this
file. There are no links here at the moment.
</p>
-------------------------------------------------------------------------------------------------

May 25 '07 #1
2 3340
On May 25, 6:34 am, "thetechturf.com" <BryanLBurkhol...@gmail.com>
wrote:
// Check for bad requests. This is necessary to prevent the wrong
files
// from being included. This is a security measure.
if (strpos($p,"..")) {
Be careful with this line! strpos() returns the numeric position of
one string within another, which can be zero (if the contained string
is the beginning). That's where it would be a problem for it to be.
What this line assumes is that strpos() will return false when it
doesn't find it, or a numeric position when it does find it. Any
number other than zero, when casted to a boolean, is true, and zero is
false. So to make sure this line works right, change it to this:
if (strpos($p,"..") !== false) {

!== means not equal to, before type casting.

So anyway, you're in a position where you might find it easier to be
using a templating library. Smarty (smarty.php.net) is standard, but
there are alternatives with (almost) the same syntax which are more
efficient, such as TemplateLite.

Otherwise, you could either search/replace the new meta tags in there
(find the </headtag, replace with "<meta ... /></head>"), or put
another variable in header.php, like <?=$description ?>, and add that
before or after that <styleelement. Example:

header.php
----------------
<html>
<head>
<title><?=$title ?></title>
<meta http-equiv="description" content="<?=$description ?>" />
<style type="text/css">
body {
background-color: white;
color: #333333;
font-family: verdana;
font-size: 11px;
}
</style>
--------------------------------------------------------------------------------------------

Then you could just assign $header in index.php like you do $title.

By the way, in <styletags, you don't need the <!-- and -->. Trying
to account for those browsers that less than 10 people on Earth still
use was about as bad of an idea as it was to type all HTML tags in
capital letters (there are way more people that don't speak English,
but do we all account for them? Every language?). If you really want
to do it anyway, you might consider using /*<!--*/ and /*-->*/ instead
so that if you ever need to put your code on one line with an output
buffer (not really efficient unless you are using output caching or
have very little traffic), it won't screw up your CSS.

-Mike PII

May 25 '07 #2
Thanks. I got this code off of the internet, so it is not original to
me. Will check out the template deal. That might be more what I am
looking for. Not sure. Thanks again for the detailed reply.

Bryan

On May 25, 4:20 pm, Mike P2 <sumguyovrt...@gmail.comwrote:
On May 25, 6:34 am, "thetechturf.com" <BryanLBurkhol...@gmail.com>
wrote:
// Check for bad requests. This is necessary to prevent the wrong
files
// from being included. This is a security measure.
if (strpos($p,"..")) {

Be careful with this line! strpos() returns the numeric position of
one string within another, which can be zero (if the contained string
is the beginning). That's where it would be a problem for it to be.
What this line assumes is that strpos() will return false when it
doesn't find it, or a numeric position when it does find it. Any
number other than zero, when casted to a boolean, is true, and zero is
false. So to make sure this line works right, change it to this:
if (strpos($p,"..") !== false) {

!== means not equal to, before type casting.

So anyway, you're in a position where you might find it easier to be
using a templating library. Smarty (smarty.php.net) is standard, but
there are alternatives with (almost) the same syntax which are more
efficient, such as TemplateLite.

Otherwise, you could either search/replace the new meta tags in there
(find the </headtag, replace with "<meta ... /></head>"), or put
another variable in header.php, like <?=$description ?>, and add that
before or after that <styleelement. Example:

header.php
----------------
<html>
<head>
<title><?=$title ?></title>
<meta http-equiv="description" content="<?=$description ?>" />
<style type="text/css">
body {
background-color: white;
color: #333333;
font-family: verdana;
font-size: 11px;}

</style>
--------------------------------------------------------------------------------------------

Then you could just assign $header in index.php like you do $title.

By the way, in <styletags, you don't need the <!-- and -->. Trying
to account for those browsers that less than 10 people on Earth still
use was about as bad of an idea as it was to type all HTML tags in
capital letters (there are way more people that don't speak English,
but do we all account for them? Every language?). If you really want
to do it anyway, you might consider using /*<!--*/ and /*-->*/ instead
so that if you ever need to put your code on one line with an output
buffer (not really efficient unless you are using output caching or
have very little traffic), it won't screw up your CSS.

-Mike PII

May 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mark | last post by:
I have been working for quite some time on this issue which in theory should be quite simple. The problem is that the Cancel and Save events are not fired when their respective buttons are...
4
by: Tim::.. | last post by:
Can someone please tell me why the following dynamic refresh doesn't work! Thanks Inline code... <!----- dynamically filled META REFRESH element -----> <meta id="mtaRefresh" runat="server" />...
6
by: Fred Nelson | last post by:
Hi: I'm developing a new C# Web App and I'm hoping to find a way that I can dynamically generate meta tags for the search engines at the page level. (I want to do this so that I can have someone...
3
by: samuelberthelot | last post by:
Hi, In one of my database's tables I have a Header and Footer field, which content is used to create the header and footer of my Master page. Part generated from Header field: <html > <head...
2
by: Dst | last post by:
<head runat="server"> <noscript> <meta http-equiv='refresh' content='0;url=Unsupported.htm'/> </noscript> </head> If i add this to my webform, it redirects to Unsupported.htm if javascript...
1
by: Martin Mücke | last post by:
I got a website consisting of about 150 php pages. The site uses a frameless table based design. Header and menu are always the same and therefore should be extracted. At the moment I got a...
4
by: bashetty | last post by:
Well its a strange problem i have, some of you might already faced it and have a solution. I have to maintain a set of unique "search key words" in meta tags for each content page in my site. With...
21
by: karen987 | last post by:
I have a news website, with asp pages. It has publishing software which allows you to add articles in a database, and then calls them up from links etc. I have added dynamic meta tags in 2 parts. The...
5
by: Nick | last post by:
Hi there, I am adding a meta redirect tag to the page dynamically on 2 separate pages in asp.net. One of the pages it works fine, and 5 seconds after the page appears, the redirect occurs. On...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.