SEO
Code Tips
Marketing
Portfolio
Resources

Google

Web Programming Tips and Tricks PHP Apache MySQL



Web programming tips and tricks free code and tutorials.


Using PHP MySQL and Apache to make database driven pages look static. When makin a web site you propbably have many pages such as a product pages which are the same except for the product information found on the page. You could make the site database driven and call the pages through the url variables like this(productpage.htm?id=41). This would pull the product page for the product corresponding to id 41 in the products database. Another way to do this which will make your site appear to have many more pages is by using apache directives, php string functions, and a mysql database to make pages look like this (productpage/widget.htm). To begin add these commands to Apache httpd.conf file.

1)<Files ~ "productpage">
AcceptPathInfo On
</Files>
2)<Location /productpage>
ForceType application/x-httpd-php
</Location>
3)
<Files "*.htm">
ForceType application/x-httpd-php
</Files>


The first line tells Apache to ignore anything in the url beyond productpage. The seconfd line tells apache to parse productpage with no extension as a PHP file.The third line tells apache to parse all .htm files as PHP.

Optionally you may only have access to your .htaccess file. In this case you will need to add this code to your .htacess file.
1)AddHandler server-parsed .php

2)<Files index2>
SetHandler application/x-httpd-php
</Files>

3)AddHandler application/x-httpd-php .php .html .htm

The next step in this process is to make a php page called prodcutpage with no extension. This page will parse the url to find which product to pick out of the MySQL database. Here is a portion of the code you will nedd to parse the url and picjk the correct data from the database.

$var = explode("/",$_SERVER["REQUEST_URI"]);
$name = str_replace(".htm", "", $var[2]);

$findproduct = query("select * from products where productname = '".. trim(strtr($name, "-"," ")) ."' ");