Get the right metatags from database, based on loaded page

Hi all,

I am really a newbie here, so pleae have patience with me.

I’ve got an index page where all my other pages will load. My pages are conected to the database and are getting different records. What i am trying to do, is to load the correct(to be similar with the pages loaded) metatags…title…description,into my index page.

Can you please give an ideea what to use, or how to do it?

Thank you!

I have recently coded a hidden session variable on http://johns-jokes.com that
displays the title, keywords and description for all the pages on my site.

I have enclosed the following screen-dump:
http://www.graabr.com/l3E1PX/

What I do is to get the $title and $description from my database and to use it in my pages:




// header
<head>
<title><?php echo $title;?></title>
<meta name=‘keywords’ content=‘<?php echo $keywords; ?>’ />
<meta name=‘description’ content=‘<?php echo $description;?>’ />



</head>

Can you please show me the script for the session? I want to see if there is any connection to the id from the database.

The output is relative easy, the association is giving me trouble.

Thank you!

I am not sure what you want but here is the code to save_session,php:



  
<?php 

session_start();

error_reporting(E_ALL);
ini_set('display_errors', 'On');

if ($_POST)
{
  $_SESSION['my_localhost'] = $_POST['my_localhost'];
}
?>

<form name="input" action="save_session.php" method="post">
	
  <label><?php echo $_SERVER['SERVER_ADDR']; ?></label>
	<input type=ínput' name='my_localhost' value='<?php echo $_SERVER['SERVER_ADDR']; ?>' />
  <input type='submit' name='submit' />

</form>

<a href='/'>Johns-Jokes.com</a>
<br /><br /><br />

<?php
	echo '$_SESSION["my_localhost"] ==> ';
	echo isset($_SESSION['my_localhost']) ? $_SESSION['my_localhost'] : 'Not set';
	// $_SESSION['my_localhost'] = 'NOT_SET';


Sorry for not explaining to good. I need to learn more english also. :slight_smile:

ok, this is my database(one of the tables):

seo (
id int(255) NOT NULL AUTO_INCREMENT,
actor_nume text COLLATE utf8_unicode_ci NOT NULL,
album_nume text COLLATE utf8_unicode_ci NOT NULL,
page_title text COLLATE utf8_unicode_ci NOT NULL,
meta_keywords text COLLATE utf8_unicode_ci NOT NULL,
meta_description text COLLATE utf8_unicode_ci NOT NULL,
image varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
alt_tag text COLLATE utf8_unicode_ci NOT NULL,
cloud_tags text COLLATE utf8_unicode_ci NOT NULL,
album_description text COLLATE utf8_unicode_ci NOT NULL,
actor_description text COLLATE utf8_unicode_ci NOT NULL,
h1 text COLLATE utf8_unicode_ci NOT NULL,
title text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

my index.php is under root folder

the pages which will load in index.php are under root/pagini/

when the pages from root/pagini/ will load in my index.php(under root), i want the information from seo table to be ‘echoed’ in my index.php, but to be the right data for each record.

the pages under root/pagini/ have sql queries also, getting different records from the database.

This is what i did:

on my included pages under root/pagini/, every page has this code, with different id to get different record from database:

<?php // this starts the session
session_start();

// this sets variables in the session
$_SESSION[‘id’] = $_POST[‘$id’];
$_SESSION[‘actor_nume’] = $_POST[‘$actornume’];
$_SESSION[‘album_nume’] = $_POST[‘$albumnume’];
$_SESSION[‘meta_keywords’] = $_POST[‘$metakey’];
$_SESSION[‘page_title’] = $_POST[‘$pagetitle’];
$_SESSION[‘meta_description’] = $_POST[‘$metadesc’];
$_SESSION[‘image’] = $_POST[‘$image’];
$_SESSION[‘alt_tag’] = $_POST[‘$alttags’];
$_SESSION[‘cloud_tags’] = $_POST[‘$cloudtags’];
$_SESSION[‘album_description’] = $_POST[‘$albumdesc’];
$_SESSION[‘actor_description’] = $_POST[‘$actordesc’];
$_SESSION[‘h1’] = $_POST[‘$h1’];
$_SESSION[‘title’] = $_POST[‘$title’];
end(); ?>
<?php
include (“condb.php”);

$query=“SELECT * FROM seo WHERE seo.id=2”;
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,“id”);
$actornume=mysql_result($result,$i,“actor_nume”);
$albumnume=mysql_result($result,$i,“album_nume”);
$pagetitle=mysql_result($result,$i,“page_title”);
$metakey=mysql_result($result,$i,“meta_keywords”);
$metadesc=mysql_result($result,$i,“meta_description”);
$image=mysql_result($result,$i,“image”);
$alttags=mysql_result($result,$i,“alt_tag”);
$cloudtags=mysql_result($result,$i,“cloud_tags”);
$albumdesc=mysql_result($result,$i,“album_description”);
$actordesc=mysql_result($result,$i,“actor_description”);
$h1=mysql_result($result,$i,“h1”);

On my index.php under root i put this code:

<?php
// this starts the session
session_start();
$_SESSION[‘id’];
$_SESSION[‘actor_nume’];
$_SESSION[‘album_nume’];
$_SESSION[‘meta_keywords’];
$_SESSION[‘page_title’];
$_SESSION[‘meta_description’];
$_SESSION[‘image’];
$_SESSION[‘alt_tag’];
$_SESSION[‘cloud_tags’];
$_SESSION[‘album_description’];
$_SESSION[‘actor_description’];
$_SESSION[‘h1’];
$_SESSION[‘title’];
?>

When i try to output the file like this:

<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title><?php print $_SESSION[‘title’]; ?></title>
<meta name=“google-site-verification” content=“rm3s8qlIYPX4_gekZXiMewICGfMew66DnKQWOm9NgBQ” />
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
<meta name=“description” content=“Colectia Mari actori romani. <br> Cand teatrul, muzica si poezia se intalnesc atunci se naste arta. <?php print $_SESSION[‘meta_description’]; ?>">
<meta name=“keywords” content="<?php print $_SESSION[‘meta_keywords’]; ?>”>

the only data showed is this(that is showing correct):
<title><?php print $_SESSION[‘title’]; ?></title>

the other ones
<?php print $_SESSION[‘meta_description’]; ?> and
<?php print $_SESSION[‘meta_keywords’]; ?>

are not returning nothing

I am confused with your code but anyway maybe try this:

Include the following lines of code in index.php


 &lt;?php 
    session_start(); 
    error_reporting(E_ALL); 
    ini_set('display_errors', 'On'); 
 
function check_session($msg='Display session elements')
{  
   echo $msg;
    echo '&lt;pre&gt;';
       print_r($_SESSION);
    echo '&lt;/pre&gt;';
}
  
// test to see the session elements
  check_session('First test');


Also use the above function before and after loading your session variable from the database.

I am confused also :), and i know the code is not good, that’s why i needed somebody to lightupi my brains.

This is what i get after putting the code you provided:

st test

Array
(
[mariactori_arUserLevel] => Array
(
)

[mariactori_arUserLevelPriv] =&gt; Array
    (
    )

[mariactori_status] =&gt; login
[mariactori_SysAdmin] =&gt; 1
[mariactori_status_UserName] =&gt; Administrator
[mariactori_actori_where] =&gt; 
[mariactori_actori_start] =&gt; 1
[mariactori_actori_return] =&gt; http://www.mariactoriromani.ro/admin1/actorilist.php
[mariactori_Message] =&gt; 
[mariactori_album_where] =&gt; 
[mariactori_album_start] =&gt; 1
[mariactori_album_return] =&gt; http://www.mariactoriromani.ro/admin1/albumlist.php
[mariactori_album_continut_where] =&gt; 
[mariactori_album_continut_start] =&gt; 1
[mariactori_album_regie_where] =&gt; 
[mariactori_album_regie_start] =&gt; 1
[mariactori_album_regie_return] =&gt; http://www.mariactoriromani.ro/admin1/album_regielist.php
[mariactori_seo_where] =&gt; 
[mariactori_seo_start] =&gt; 1
[mariactori_seo_return] =&gt; http://www.mariactoriromani.ro/admin1/seolist.php
[id] =&gt; 2
[actor_nume] =&gt; 
[album_nume] =&gt; 
[page_title] =&gt; 
[meta_keywords] =&gt; 
[meta_description] =&gt; 
[image] =&gt; imagine test
[alt_tag] =&gt; 
[cloud_tags] =&gt; 
[album_description] =&gt; 
[actor_description] =&gt; 
[h1] =&gt; h1 test
[title] =&gt; titlu test

)

the index.php
http://www.mariactoriromani.ro/index1.php

the testing page here
http://www.mariactoriromani.ro/index1.php?pg=pagina_test

I tried one of the links you gave, highlighted the page and the following errors were displayed:

First test

Array
(
)


Notice: Undefined index: id in /home/mari/public_html/index1.php on line 18

Notice: Undefined index: actor_nume in /home/mari/public_html/index1.php on line 19

Notice: Undefined index: album_nume in /home/mari/public_html/index1.php on line 20

Notice: Undefined index: meta_keywords in /home/mari/public_html/index1.php on line 21

Notice: Undefined index: page_title in /home/mari/public_html/index1.php on line 22

Notice: Undefined index: meta_description in /home/mari/public_html/index1.php on line 23

Notice: Undefined index: image in /home/mari/public_html/index1.php on line 24

Notice: Undefined index: alt_tag in /home/mari/public_html/index1.php on line 25

Notice: Undefined index: cloud_tags in /home/mari/public_html/index1.php on line 26

Notice: Undefined index: album_description in /home/mari/public_html/index1.php on line 27

Notice: Undefined index: actor_description in /home/mari/public_html/index1.php on line 28

Notice: Undefined index: h1 in /home/mari/public_html/index1.php on line 29

Notice: Undefined index: title in /home/mari/public_html/index1.php on line 30
  	

These errors need to be fixed.

I am off to bed and hopefully another poster can provide a solution.

ok, i will try to see what is the problem.
thank you for your time.