开发者

How can I create a user-generated page on my website?

For example, say if a user wanted to 'add a place' to my database, how could I create a page almost instantly with that place's name in the domain e.g www.mydomain.com/placename?

I understand it might be a complex solution so if it is too complex to explain can you please push me into the right direction 开发者_运维问答of what I should be researching.


  • Create functionality to create "pretty urls" in php. Read more about that here: http://www.roscripts.com/Pretty_URLs_-_a_guide_to_URL_rewriting-168.html
  • Create parsing functionality for the urls, so that it recognizes "/placename" as the page "placename"
  • Create a database structure for pages with the page id, title, content and the url slug, etc.
  • Create functionality to fetch the right page from the database according to the matching url slug.
  • Create functionality to render the retrieved informaton

If I understood you right that's one approach to what you want to do.


I'm assuming you're using Apache. If so, create a rule using mod_rewrite that forwards requests for /place/placename to /place.php?name=placename. Then write the place.php script, which will pull the user page from the database and display it in the appropriate fashion.

That's one way to do it - there are others.


First of all try to understand mod rewrite. You could "mask: a GET url into a much nicer format.

Start here : http://www.elated.com/articles/mod-rewrite-tutorial-for-absolute-beginners/

Then google on and get yourself familiar with all the possibilities.

After that make sure the GET variable is unique in your database, to be absolutely sure use a unique ID.

Example :

domain.com/PLACEID/PLACENAME/ 

mod_rewrite could then translate this to your php script into :

domain.com/place.php?VAR=PLACEID&VAR2=PLACENAME

Search the data from the user/place through the PLACEID .

Good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜