Forum Moderators: coopster
$page = isset($_GET['page']) ? $_GET['page'] : 'home'; <?php
// Open database here...
// SQL
$sql = mysql_query("SELECT * FROM database WHERE id = '" . $id . "' LIMIT 1") or die (mysql_error());
while($row = mysql_fetch_array($sql)){
$title = $row['title']; // get title from database
$description = $row['description']; // get description from database
$keywords = substr($row['keywords'], 0, 250); // get keywords (250 characters) from database
}
// Close database here...
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php echo $title?></title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta http-equiv="Content-Language" content="en">
<meta name="description" content="<?php echo $description?>">
<meta name="keywords" content="<?php echo $keywords?>">
</head>
<body>
<!-- HTML content goes here... -->
</body>
</html>
$sql = mysql_query("SELECT * FROM database WHERE id = '" . $id . "' LIMIT 1") or die (mysql_error()); $sql = mysql_query("SELECT * FROM database WHERE id = '" . $page . "' LIMIT 1") or die (mysql_error()); <?php
$localhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'mydb';
$connect = mysql_connect($localhost, $dbuser, $dbpass);
mysql_select_db('dbname', $connect);
$page = array('about','profiles','another_page');
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$sql = mysql_query("SELECT * FROM mydb WHERE id = '" . $page . "' LIMIT 1") or die (mysql_error());
if( mysql_num_rows($sql) ) {
$row = mysql_fetch_array($sql);
$title = $row['title']; // get title from database
$description = $row['description']; // get description from database
$keywords = substr($row['keywords'], 0, 250); // get keywords (250 characters) from database
} else {
$title = 'Set Default Title';
$description = 'Set Default Description';
$keywords = 'Set Default Keywords';
}
include($_SERVER['DOCUMENT_ROOT']. '/include/header.php');
include('content/'.$page.'.php');
include($_SERVER['DOCUMENT_ROOT']. "/include/footer.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php echo $title?></title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta http-equiv="Content-Language" content="en">
<meta name="description" content="<?php echo $description?>">
<meta name="keywords" content="<?php echo $keywords?>">
</head>
<body>
<!-- HTML content goes here... -->
</body>
</html>
will this work or not.
My site will be a large site so what is your recommendations?
<?php require_once($_SERVER['DOCUMENT_ROOT']. "/include/config.php");
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$sql = $mysqli->query("SELECT * FROM admin WHERE id = '" . $page . "' LIMIT 1");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if ($sql->num_rows > 0) {
$row = $sql->fetch_object();
$title = $row['title']; // get title from database
$description = $row['description']; // get description from database
$keywords = substr($row['keywords'], 0, 250); // get keywords (250 characters) from database
} else {
$title = 'Administration Panel';
$description = 'description';
$keywords = '';
}
$sqlb = $mysqli->query("SELECT * FROM config");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if ($sqlb->num_rows > 0) {
$rowa = $sqlb->fetch_object();
$url = $rowa['adminurl'];
$email = $rowa['support_email'];
$legal = $rowa['legal'];
}
include($_SERVER['DOCUMENT_ROOT']. "include/header.php");
include('content/'.$page.'.php');
include($_SERVER['DOCUMENT_ROOT']. "include/footer.php");
?>
Let me guess. You're going to write specific code if the page parameter is invalid and return 404? How about parameter qwerdhfj? It's also invalid.
A simple way to filter that URL: if it's a url, you're only going to allow letters, numbers, and dashes, right?
$text = preg_replace('/[^a-z0-9]+$/', '', (preg_replace('/[^a-z0-9-]+/', '-', (preg_replace('/[\']+/', '', (preg_replace('/\ ?&\ ?/', '-', strtolower($this->pageName)))))))); & with hyphen -> remove apostrophes -> replace non-a-z non-0-9 non-hyphen with a hyphen. example.com/page434-the-page-name-is-here [edited by: g1smd at 7:24 pm (utc) on Apr 24, 2012]
The code shown below has served well on many occasions for generating the text part of a priendly URL from the page title:
$text = preg_replace('/[^a-z0-9]+$/', '', (preg_replace('/[^a-z0-9-]+/', '-', (preg_replace('/[\']+/', '', (preg_replace('/\ ?&\ ?/', '-', strtolower($this->pageName)))))))));
The code shown below has served well on many occasions for generating the text part of a friendly URL from the page title: