views:

57

answers:

2

For example, when a user adds a question to a Q&A site, that question typically gets its own web page, and that web page was created on-the-fly. How can you do this with PHP? Could anyone point me to any resources? Thanks.

+2  A: 

"How to" on this is bigger than a normal Stackoverflow question.

Maybe have a look here for some ideas(I'm just quickly scanning through it right now, can't really say if it's a great tutorial or not right now): http://www.tuttoaster.com/how-to-create-a-forum-in-php-from-scratch/

If you're a php novice, it may be better to look for one of the open source PHP forum applications like http://www.phpbb.com/ or something like that (phpbb just being the first that came to mind). That will be a lot more code to sort through, but the more popular open source applications will likely already know how to deal with security concerns like cross site scripting attacks and sql injection attacks.

Jim Leonardo
+3  A: 

By "that question typically gets its own web page" you are referring to "gets its own url". For example, this one is http://stackoverflow.com/questions/3723813/how-do-you-allow-users-to-dynamically-create-a-web-page-within-a-web-app.

It's really just a trick. Very simplified:

  • When you submitted this question, it got a unique identifier 3723813 and was inserted into a database.
  • There is a single controller script that deals with questions, say http://stackoverflow.com/questions.php
  • When someone tries to open this page, the server knows to send it to questions.php by using a module such as mod_rewrite for apache.
  • Then, questions.php looks at the url parameters, takes the unique id for this question, 3723813, and loads up its information from the database in order to display it.
  • The rest of the url is just cosmetic and just there so that we can right away know what question it is before opening the page.
Fanis