Auto head "<head></head>". PHP & MYSQL

Information for PHP. Hypertext Preprocessor
Post Reply
dzcadii
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Auto head "<head></head>". PHP & MYSQL

Post by dzcadii » Sun Mar 01, 2015 6:38 pm

Ok, so you are tired of typing in the <head> information and you are using PHP and MYSQL. You can try this out. You can even set it for spiders (allow them to crawl or not).

Code view: (tired of typing)

Code: Select all

<html>
<head>
<meta name="description" content="I am a description and we can go on forever with this">
<meta name="keywords" content="We,Are,Keywords,Cars,Trucks,Scripting and ECMA scripts">
</head>
<body>
You can adapt the script and yes, it does support multiple pages with unique meta data
</body>
</html>
This consist of 2 files. the class file and every page you want to use the AutoHeader in.
//AutoHeader Function By: DzCADII @ http://dzsoundnirvana.com/

/***************************************************************************
This is how the database table should be set up. This is a dump from the DB. Make sure you change the db name and table in the SQL
***************************************************************************/

Code: Select all

-- Database: `Your DB name`
-- Table structure for table `pages`

DROP TABLE IF EXISTS `pages`;
CREATE TABLE IF NOT EXISTS `pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app` varchar(255) NOT NULL,
  `action` varchar(255) NOT NULL,
  `Title` varchar(255) NOT NULL DEFAULT '',
  `META_DES` longtext NOT NULL,
  `META_KW` varchar(255) NOT NULL DEFAULT '',
  `Crawl` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Page METAT Data' AUTO_INCREMENT=9 ;
/*****************************************************************************
The class. in a separate file "heads"
*****************************************************************************/

Code: Select all

<?
class heads{
	function heads($UserInput){
	}
	function GetMETA($UserInput){
		$this->GetDB(Link information);
			$META=mysql_query("SELECT * FROM HeadTable WHERE app='$UserInput[app]' && action='$UserInput[action]'");
				$METAInfo=mysql_fetch_assoc($META);
					if($METAInfo['Crawl']==0){
						echo "<!-- Begin AutoHeader Function By: CADII @ http://dzsoundnirvana.com/ -->n<title>$METAInfo[Title]</title>n<meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOIMAGEINDEX,NOIMAGECLICK">n<meta name="description" content="$METAInfo[META_DES]">n<meta name="keywords" content="$METAInfo[META_KW]">n<!-- End AutoHeader -->n";
					}
					else{
						echo "<!-- Begin AutoHeader Function By: CADII @ http://dzsoundnirvana.com/ -->n<title>$METAInfo[Title]</title>n<meta name="description" content="$METAInfo[META_DES]">n<meta name="keywords" content="$METAInfo[META_KW]">n<!-- End AutoHeader -->n";
					}
	}
//You need to customize this function to link to your database
	function GetDB(Link information){
		$link=mysql_connect(['dbhost'],['dbuser'],['dbpassword']);
		$sel_db=mysql_select_db(['db']);
	}
}
?>

/****************************************************************************
Time to call the class in each <head>. Lets say index.php
****************************************************************************/
<?
//Set Page ID
$PageID=md5($_SERVER['PHP_SELF']);
?>
<head>
<?
$UserInput=array();
foreach($_GET as $key => $value){
	$UserInput[$key] = $value;
}
require('path to your class');
$heads=new heads($UserInput);
	$META=$heads->GetMETA($UserInput);
?>
//Here are somethings you should know
1. The $UserInput array is generated from $_GET. I passed information to get the $app and $action. You can use what ever you want in the URL/Href like this
<a href="index.php?app=0&action=0">Click this</a>
2. in the database table you will have to set the field app to 0 and action to 0 then apply all of the other information.

//This is just a low down and dirty example. It should give you some direction of how to complete this task......
If you need help contact support@dzsoundnirvana.com
Good Luck

Post Reply