Forum Moderators: coopster

Message Too Old, No Replies

On the Fly Page Creation

         

jp_css

10:59 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



I have a quick and possibly easy question. I would like to create pages on the fly by having all of the file names in a database (there are 1000s of files so it would be nice to save on room) by seperate pages. For example: [example.com...] Is there a way if someone was to access that page (it doesn't physically exist on the server) that it could be created through php based on if it's in the db?

jp_css

12:38 am on Mar 25, 2004 (gmt 0)

10+ Year Member



Does this even make sense?

Timotheos

12:52 am on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes it's possible... I remember a thread on this but I can't find it. Arrgh!

jp_css

1:03 am on Mar 25, 2004 (gmt 0)

10+ Year Member



Cool, anyone have any clue where the thread is or how to do this?

jp_css

1:39 am on Mar 25, 2004 (gmt 0)

10+ Year Member



In other words:

I would rather have:

[example.com...]
rather than:
[example.com...]

Elijah

2:03 am on Mar 25, 2004 (gmt 0)

10+ Year Member



Here's a rought sketch of what you could do. (I do something like this except more complicated.)

1. Use ModRewrite to send all requests that are not images or css files to index.php
In an .htaccess file put:


RewriteEngine on
RewriteRule!\.(gif¦jpg¦png¦css)$ index.php

Replace all broken pipes "¦" with solid pipe characters from your keyboard

Then in index.php do something like this:


<?php
$uri=strip_tags($_SERVER['REQUEST_URI']);

$query="SELECT id,title,description,content FROM pages WHERE uri='$uri'";
$result=mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) { echo 'Error: No Matching Page'; }
$page=mysql_fetch_assoc($result);

?>
<html>
<head>
<title><?php echo $page['title'];?></title>
<meta name="description" content="<?php echo $page['description'];?>" />
</head>
<body>
<?php echo $page['content'];?>
</body>
</html>

In the database you would have something like


id ¦ URI ¦ page_title ¦ description ¦ content ¦
1 ¦ /mypage.html¦My Super Page ¦ My page is about... ¦ Pagecontent here¦

For mysql you could use something like:

# Table structure for table `pages`
#

CREATE TABLE `pages` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`uri` varchar(255) NOT NULL default '',
`title` varchar(255) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`content` mediumtext NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uri` (`uri`),
FULLTEXT KEY `fulltext_index` (`title`,`content`,`description`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

#
# Dumping data for table `pages`
#

INSERT INTO `pages` VALUES (1, '/mypage.html', 'Title of Page', 'A small but growing collection or original pages by various authors', 'Welcome to my page!');

The above code is not all tested. If you have any problems or questions feel free to post back and I'll try to help. ;)

Elijah