Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I get a PHP CMS page to create an HTML file and save it to the UNIX server?

Posted on 2007-04-03
5
Medium Priority
?
265 Views
Last Modified: 2013-12-12
Hi.
I am designing a website for performers, using PHP and MySQL.

I need the CMS (which I am building) to be able to delete/ edit and add performers.  No problem, but the way I would usually do this is so that the performers web page would look something like this:

www.thiswebsite.co.uk/performer.php?id=22
or
www.thiswebsite.co.uk/performer.php?id=Mr Big Top

But I really need the URL to be

www.thiswebsite.co.uk/performer/Mr Big Top.html and for the file to exist...

I know I can pass HTML through the PHP compiler, so I can execute PHP in HTML, but, and HERE'S THE QUESTION:

How can I get a PHP CMS page to create an HTML file based on a template, and save it to the UNIX server so it can be accessed?

 
0
Comment
Question by:CrisThompsonUK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 1200 total points
ID: 18844638
If this is going to be a dynamic site, I would recommend against creating a static page like 'Mr Big Top.html'. However, you can use a rewrite in Apache to allow users to browse to a URL like "www.thiswebsite.co.uk/performer/Mr_Big_Top.html", but in the background you are realling calling a page like "www.thiswebsite.co.uk/performer.php?id=Mr_Big_Top". The users of your site will never know the difference, because the only thing they will see in the address bar is "www.thiswebsite.co.uk/performer/Mr_Big_Top.html".

For more information, see http://www.articlestree.com/search-engines/mod-rewrite-for-dummies-tx134817.html

Note: Spaces are usually not a good idea in a URL, because some browsers and/or webservers will not interpret them correctly. You should either drop the spaces, or replace them with something like underscores as I did in my above.
0
 
LVL 5

Expert Comment

by:richswyatt
ID: 18844651
Read the file with fopen() then fread() to get the contents of the template...
Parse through it and insert the data where needed.

fwrite the contents to a file. If you need to create folders through the CMS then you'll need to use execute() to execute a "mkdir" command (provided that the user running the Apache service has rights to execute command line...
0
 

Author Comment

by:CrisThompsonUK
ID: 18844720
glcummins

I see you are a master..  I am humbled.

The reason for all lthis is that we are replacing a static (HTML) site with a dynamic one, and we need to try to keep the page rankings as much as possible undisturbed, so the system needs to be able to crate new performers, but these need to be visible to search engines and browsers as whoever.html.

What would you suggest as the best way to achieve this?

cris.
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 800 total points
ID: 18845087
Use mod_rewrite for this. Its the best solution for that. You have .html-urls, but always up to date content without the need to sync your content from the database to the disk-files.

RewriteRule ^/performer/(.*).html$ /performer.php?id=$1 [R]

See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
0
 

Author Comment

by:CrisThompsonUK
ID: 18996774
Thanks guys...

300 for glcummins for setting me straight in the first place, and 200 for hernst42 for having a go at the actual syntax...

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question