PHP flat file comment engine -- Design

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    PHP flat file comment engine -- Design

    Greetings all,

    The host I use does not let me have mysql so I am going to need to write a comment engine that uses flat files. Unless of course there are commenting solutions already available that do not use mysql.

    So now lets talk about how this is going to work... (your input is appreciated). I think we are going to need a couple things, an admin panel and the UI. The user is going to need a UI, so we will have a few fields, probably name, email address, comment area, and a captcha. Captcha is needed to prevent spam. The user will fill out the form, (name, comment and captcha will be required) and the comment will be stored in a file somewhere. Now this is where it gets a little tricky because I'm not a web programmer, the comment gets stored in a file, the file will need to have some kind of identifier that maps it to the page that is being commented on. Then the rendering php will grab the comment information in the file and reload the page with the comments rendered at the bottom.

    How is that for a preliminary idea. Anyone have any thoughts on important cases that have not been considered? We haven't looked at the admin side of this yet but I want to get one side working before I start in on the other.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, RedSon.

    You have a couple of options. You could create a separate comments file for each page. Alternatively, you could prefix each comment with the name of the page.

    There's advantages and disadvantages to each method.

    Using separate files is great for viewing comments on a per-page basis, but it isn't quite so good at viewing comments for more than one page (such as, "show me the 5 most recent comments").

    Using one big file makes it more of a pain to view comments per-page, but aggregate stuff is much easier.

    I suppose you could create 'index' files by assigning each comment a unique identifier and then creating one big file to hold all of the comments, and then index files that list id numbers per page....

    This all depends, of course, on whether you're getting paid per project or per hour :P

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      Originally posted by pbmods
      Heya, RedSon.

      You have a couple of options. You could create a separate comments file for each page. Alternatively, you could prefix each comment with the name of the page.

      There's advantages and disadvantages to each method.

      Using separate files is great for viewing comments on a per-page basis, but it isn't quite so good at viewing comments for more than one page (such as, "show me the 5 most recent comments").

      Using one big file makes it more of a pain to view comments per-page, but aggregate stuff is much easier.

      I suppose you could create 'index' files by assigning each comment a unique identifier and then creating one big file to hold all of the comments, and then index files that list id numbers per page....

      This all depends, of course, on whether you're getting paid per project or per hour :P
      Heh, this is strictly for fun, but I like your idea about putting them in one file. Maybe I can have a sorted tree then it would grow slowly be easiy to index and have easy ways to aggregate data. Not sure how to work that...

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Assuming that you make '|' characters illegal in comments, you could do something like this:
        [code=text]
        comment_id|page _name|comment_p oster|comment_t ext
        1|main.php|Will iam Scott|love the site!
        2|main.php|Scot t Williams|I HATE THIS SITE!
        3|main.php|Will iam Scott|o yeah? well ur dumb!!1!1!
        4|home.php|Mark |(they'll never find me)
        [/code]

        And so on.

        Then you could create a couple of index files. For example,main.ph p.idx would contain:
        [code=text]
        1
        2
        3
        [/code]

        And then if you wanted to get REALLY intricate, you could create a williamscott.id x file:
        [code=text]
        1
        3
        [/code]

        You can use file() and explode() to turn your flat files into arrays.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Of course, you could also use var_export() and just output PHP code to create an array and be done with it....

          Comment

          • jx2
            New Member
            • Feb 2007
            • 228

            #6
            for fun u said ? ;-)

            i had exactly the same problem once
            i wrote(for fun) the database engine in php :-) yeah!!
            it was faster then mysql :-) yeah:-)

            so listen to me:-)

            1. we need to know what you going to do with this data later
            2. you need search engine?
            3. how many treads you expect?(fix number?)
            4. how many posts per tread?
            5. how long is each coment?

            for know i can tell you if i were you i would use 2 files
            1 for adres user name and so on
            2 for coments

            file one fixed lenght
            lets say tread name 30, user name 30, adress 70 and position of the coment in 2th file about 10(140toghether ) fixed lengh help to serach throu data

            i would use 3th file as an index file for treads (that depends how many treads you going to have)
            you can also try to store adres of the last coment in the tread so u can easly locate the previousecoment in the same tread

            okey
            what do you think?

            lol
            i know ...

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #7
              Originally posted by jx2
              for fun u said ? ;-)

              i had exactly the same problem once
              i wrote(for fun) the database engine in php :-) yeah!!
              it was faster then mysql :-) yeah:-)

              so listen to me:-)

              1. we need to know what you going to do with this data later
              2. you need search engine?
              3. how many treads you expect?(fix number?)
              4. how many posts per tread?
              5. how long is each coment?

              for know i can tell you if i were you i would use 2 files
              1 for adres user name and so on
              2 for coments

              file one fixed lenght
              lets say tread name 30, user name 30, adress 70 and position of the coment in 2th file about 10(140toghether ) fixed lengh help to serach throu data

              i would use 3th file as an index file for treads (that depends how many treads you going to have)
              you can also try to store adres of the last coment in the tread so u can easly locate the previousecoment in the same tread

              okey
              what do you think?

              lol
              i know ...
              Yes all good design ideas. How did your code work? Are you still using it in production? Maybe you want to share some of the harder parts?

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                I also found a website that will give you a free mysql database, so I think I might try that solution with one of the comment engines I foudn that need sql databases

                Comment

                • jx2
                  New Member
                  • Feb 2007
                  • 228

                  #9
                  Originally posted by RedSon
                  I also found a website that will give you a free mysql database, so I think I might try that solution with one of the comment engines I foudn that need sql databases
                  yeah mysql is cool :-) if you can use it it save a lot of your time

                  the thing i did was bit different it collected personal detail (fixed size 1000 ppl) was simple and fast really fast.

                  how big your project going to be?

                  Comment

                  • RedSon
                    Recognized Expert Expert
                    • Jan 2007
                    • 4980

                    #10
                    Originally posted by jx2
                    yeah mysql is cool :-) if you can use it it save a lot of your time

                    the thing i did was bit different it collected personal detail (fixed size 1000 ppl) was simple and fast really fast.

                    how big your project going to be?
                    Not sure, it is so that users can comment on pages of the site. Kind of like a blog but more like a feedback type of thing then anything else.

                    Comment

                    • jx2
                      New Member
                      • Feb 2007
                      • 228

                      #11
                      then i wouldnt bother with database
                      just uuse regular expression which add coments to the recent page

                      something like ereg_replace("</body>","$newCom ent</body>",$html);
                      then replase old page with this one

                      should work fine( as long as there is no to many coments on one page)

                      regards
                      jx2

                      Comment

                      • pbmods
                        Recognized Expert Expert
                        • Apr 2007
                        • 5821

                        #12
                        Originally posted by jx2
                        something like ereg_replace("</body>","$newCom ent</body>",$html);
                        then replase old page with this one
                        Or better yet, just use str_replace(), since you don't need the regular expression overhead ~_^

                        Comment

                        • jx2
                          New Member
                          • Feb 2007
                          • 228

                          #13
                          Originally posted by pbmods
                          Or better yet, just use str_replace(), since you don't need the regular expression overhead ~_^
                          yeah yo're right :-) that would make it the simpiest data base i've ever seen :-)

                          Comment

                          Working...