Page 1 of 1

Autogenerate new pages?

Posted: Wed Nov 07, 2007 4:57 pm
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

Posted: Wed Nov 07, 2007 7:01 pm
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.

Posted: Wed Nov 07, 2007 7:59 pm
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.