Autogenerate new pages?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newbie2php
Forum Commoner
Posts: 35
Joined: Wed Nov 07, 2007 4:44 pm

Autogenerate new pages?

Post by newbie2php »

Hi all,

I am pretty new to PHP - have just been learning the basics thus far, and how to interact with mysql. It seems a very powerful language, and I want to learn alot more :)

Question - with PHP, is there anyways to autogenerate pages of a website? And when I say autogenerate I do not mean passing something into the URL using the same 'page template', I mean actully creating a new file that will be called its own name, such as http://www.mysite.com/newpagecreated.php , http://www.mysite.com/anotherpageIcreated.php etc..? (Opposed to something like http://www.mysite.com/somepage.php?page=newpage , http://www.mysite.com/somepage.php?page=anotherpage)

From reading so far I would imagine it would be sort of possible by writing to a new file when a new page is wanting to be created which is saved in the correct folder, maybe by passing a string into it containing the code for that new made page, unless there is a simpier way?

Reason I ask is because I wanted to know if I could create a site where users can easily add pages themselves via an admin area, and then choose what content is displayed, i.e a content managment system with also auto made pages incase they decide they wanted to add another page.

Hope the above makes sense. I know it will likely be hard to code (and I may not be at the level to do so), but just seeing if it was possible to do.

Many thanks
User avatar
seppo0010
Forum Commoner
Posts: 47
Joined: Wed Oct 24, 2007 4:13 pm
Location: Buenos Aires, Argentina

Post by seppo0010 »

You can easily write files using PHP.

The easiest way is using file_put_contents, or you can use fwrite for PHP older version.

Of course, your PHP Server has to have permissions for writing on the folder you want to create those files. It is a good idea to have all of them in one folder, different from your own written code.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Or you can use apache's/lighttpd's mod_rewrite, and search here, or google will give you plenty of information.

They are sometimes called clean urls.
Post Reply