PDA

View Full Version : php and metakeywords


neroma
11-27-2007, 09:35 AM
Hi there,

I know the php code to put into a client's website, but i dont know exactly where to put it. Could somebody kindly advise where abouts it should go in the following code:-

<?php
/*
$Id: index.php,v 1.1 2003/06/11 17:37:59 hpdl Exp $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright (c) 2003 osCommerce

Released under the GNU General Public License
*/

require('includes/application_top.php');

// the following cPath references come from application_top.php
$category_depth = 'top';
if (isset($cPath) && tep_not_null($cPath)) {
$categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
$cateqories_products = tep_db_fetch_array($categories_products_query);
if ($cateqories_products['total'] > 0) {
$category_depth = 'products'; // display products
} else {
$category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
$category_parent = tep_db_fetch_array($category_parent_query);
if ($category_parent['total'] > 0) {
$category_depth = 'nested'; // navigate through the categories
} else {
$category_depth = 'products'; // category has no products, but display the 'no products' message
}
}
}

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DEFAULT);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>


<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

the code I want to put in is:-
$pgHeading="onlinemortgage101.com - Helping you to improve your web site";
$pgDesc="Helping millions Refinance home and get best mortgage loan rate quotes.";
$pgKeywords="Refinance Home, Mortgage Loan, Mortgage lead, Internet Mortgage Lead Talk";


<meta name="description" content="<?php echo $pgDesc ?>"></meta>
<meta name="keywords" content="<?php echo $pgKeywords ?>"></meta>


can somebody point me in the right direction?

kind regards
neil

beu
11-27-2007, 05:20 PM
The meta description and keywords should go in the head of the page after the TITLE in terms of html. "X' marks the spot below. :)

<head>

X

<base href=....


As for the php, it's not exactly my bag. I don't see where the TITLE is coming from in the code you provided. I'd guess "Heading" but that doen't seem to be the TITLE of the page?

Maybe someone else can share their ideas?

Jazajay
12-06-2007, 03:49 AM
you want to find the header.php file and put it in there. Thats the title etc.. include file.

Marcia
12-06-2007, 05:19 AM
the code I want to put in is:-
$pgHeading="onlinemortgage101.com - Helping you to improve your web site";
$pgDesc="Helping millions Refinance home and get best mortgage loan rate quotes.";
$pgKeywords="Refinance Home, Mortgage Loan, Mortgage lead, Internet Mortgage Lead Talk";


<meta name="description" content="<?php echo $pgDesc ?>"></meta>
<meta name="keywords" content="<?php echo $pgKeywords ?>"></meta> neroma, I could be way off-base because I'm right at the first step of the learning curve, but I believe the variables you're calling with "echo" in the meta description and keywords tags have to be defined and the value assigned to the variables within your beginning <?php and ending ?> php tags, which would be before your doctype declaration.

Jazajay
12-06-2007, 12:12 PM
Not really variables can be defined where ever including before the doctype.

So if you wrote.
<head>
<?php $header = "headerVariable";echo "$header"?>
</head>
it would output the variable, as it was defined before the echo.

However the variable has to be defined before the echo so
echo "$header";$header = "headerVariable"

would make no sense as when it came to echo the $header variable it wouldn't have been defined. That said if you want you can define all your variables before the doctype but it's not nesercary.
I prefer not to for the following reasons -
1. you can forget which variables have be cleaned (you do clean your data right)
2. they can be overridden depending on the complexity of your code.
3. I find debugging is easier if the code echo'ed is defined close by.
4. Any global variables should be set to a constant. These I tend to be at the top, again don't have to just the way I write the code.

So yeah you can but it is not nesercary.

To change your code you need to find the header.php file and change the contents in that file as that contains the meta data. If you have problems implanting post again.

One other consideration to make is if
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
is called in on the top of every page. If it is, unless it is ridiculously complex and test the pages header and displays code for each page, you will end up having the same meta tags on every page. You don't want this. I would say if this is the case just delete that line and implement your code directly on the page.

However make sure that no global variables (as in variables that are used on every page) are set in that file. If they are and you delete them you will have a slight issue.

Also you will need to pay attention to this line -
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DEFAULT);

If $language contains tainted data you will have a security issue.