I am having problems getting a read page to be created properly to a file.
Basically I have a page called view_product.php and everything is shown via view_product.php?product=12345
So, I thought why not create a static page as well named after the product title in the database, because search engines will list them and all of my content will be pointing towards view_product.php anyways.
Could you give some input on how to do this properly? Here is my major problem. I use this code to get the new file's content:
$page_name = $title;
$page_name = strip_tags($page_name);
$page_name = stripslashes($page_name);
$page_name = str_replace(" ", "", $page_name);
$page_name = htmlspecialchars($page_name);
$page_name = str_replace("'", "", $page_name);
$page_name = str_replace("&", "", $page_name);
$page_name = str_replace(""", "", $page_name);
$page_name = strtolower($page_name);
$page_db = $page_name;
$page_name .= ".php";
$file_url = "website_url_here/view_product.php?product=123456";
$file_url = str_replace(" ", "%20", $file_url);
//replace all url spaces
$file = fopen($file_url, "r");
if (!function_exists('file_get_contents')) {
$read = fread($file, 800000);
} else {
$read = file_get_contents($file_url);
}
//read our to be new file's content
$handle = "website_root_here/products/".$page_name;
if (!$open = fopen($handle, "a")) { echo "Cannot open file"; }
if(!chmod($handle, 0755)){ echo "Cannot change permission on file."; }
if (!fwrite($open, $read)) { echo "Cannot write to file ".$handle."<br>"; }
What I get is an error saying that there is no product to display. When I print out what it is seeing for $product it shows "view_product" without the quotes, it is being called over from the previous setting. Like it doesn't know what the $product variable is supposed to be from reading the file. It is reading unposted data.
Do you know how to automatically post it and then read the file to create the new one? I basically need to find out how to make it know.
Thanks for your suggestions thus far.