#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    America (But which one?)
    Posts
    43
    Rep Power
    2

    CMS without a Database


    Hello all!

    I have a website with 25 headers and 25 paragraphs, and I want to be able to edit it without viewing any of the HTML and without utilizing a database, hence this post!

    I started with a PHP script found here on devshed, which simply displays my websites content on the admin page. It is set-up on my site as in the following example (a direct excerpt from my site):

    HTML:
    Code:
    <leftcolumn>
    	<h1><!--Page1LeftColumnH1-->Header 1<!--EndPage1LeftColumnH1--></h1>
    	<p><!--Page1LeftColumnP1-->Paragraph 1<!--EndPage1LeftColumnP1--></p>
    </leftcolumn>
    PHP (on separate admin php page):
    PHP Code:
    <leftcolumn>
        <h1>
            
            <?php
            $content 
    file_get_contents('http://www.intelligenceordeath.com'FALSE);
            
    $start '<!--Page1LeftColumnH1-->';
            
    $data_bit strstr($content$start);

            
    $array explode('<!--EndPage1LeftColumnH1-->'$data_bit);

            
    $data substr($array[0], 0300);

            echo 
    $data;
            
    ?> 
            
        </h1>
        <p>    
            
            <?php
            $content 
    file_get_contents('http://www.intelligenceordeath.com'FALSE);
            
    $start '<!--Page1LeftColumnP1-->';
            
    $data_bit strstr($content$start);

            
    $array explode('<!--EndPage1LeftColumnP1-->'$data_bit);


            
    $data substr($array[0], 0300);

            echo 
    $data;
            
    ?>
        </p>
    </leftcolumn>
    My question is, from here, how do I make the fields that show up on my admin page editable? I want it to pull the information from my index.html, like it does now, and turn those fields into editable fields. Then have a save button at the end of each DIV that would then save the changed data in the HTML file itself!

    Any help would be greatly appreciated!

    -DZ
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    America (But which one?)
    Posts
    43
    Rep Power
    2
    So I've made a few modifications in an attempt to get myself closer to getting this working, but I am still stuck.

    Using a form on my admin.php, I can display what the field already contains, but when I change what it says and hit submit, it takes what I inputted and just adds (echo's) it to the original data.

    Furthermore, it doesn't save what I input, and I've tried probably 10 different bits of code found online, and I can't get any of it to work.

    Here is my code. Suggestions?

    index.php
    PHP Code:
    <h1><?php echo $_POST["HomeRightColumnH1"]; ?>
    <!--HomeRightColumnH1-->
    Testing this header
    <!--EndHomeRightColumnH1-->
    </h1>
    admin.php
    PHP Code:
    <h1><?php
            $content 
    file_get_contents('index.php'FALSE);
            
    $start '<!--HomeRightColumnH1-->';
            
    $data_bit strstr($content$start);

            
    $array explode('<!--EndHomeRightColumnH1-->'$data_bit);

            
    $data substr($array[0], 24500);

            echo 
    "<form action='test.php' method='post'>
    <input type='text' name='HomeRightColumnH1' value='
    $data'>
    <input type='submit'></form> "
    ;
            
            
    ?>

    </h1>
    Here is the error I am getting; I have no clue what to put in place of the HomeRightColumnH1 value for $_POST. I've tried admin.php, index.php, and what is currently there, and all of them threw up the same error.

    [09-Aug-2013 07:30:58 America/Denver] PHP Notice: Undefined index: HomeRightColumnH1 in /home1/intelly1/public_html/index.php on line 83
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    if index.php (or any php file that includes or requires it) is not requested with POST and doesn't have "HomeRightColumnH1" in the $_POST array it will fail with that error.

    So for example if you just bring up index.php in a browser, that sends a GET request with no data.

    If you're going to access $_POST values, you first want to check if $_POST has any data, then you want to check if the value is set, like so:

    Code:
    if ($_POST && isset($_POST["HomeRightColumnH1"]){
     //Do something with the variable
    }
    If you aren't using a database, how are you planning to persist the data?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    Paraná
    Posts
    1
    Rep Power
    0

    I think there is a mistake


    I may be wrong but if you want to be indexed by Google it will bring you some problems since you are not using a database. It will be hard to set description and title tags since you do not have a database.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    America (But which one?)
    Posts
    43
    Rep Power
    2
    Originally Posted by admoore
    If you aren't using a database, how are you planning to persist the data?
    Thank you for your reply admoore!

    If I'm not mistaken, "persist the data" refers to where the data is stored and retrieved from? If so, I was thinking that the data would be directly written to my admin.php file . . .

    I feel like I am drowning in this. I feel as though I'm not asking the impossible, but I can't find anything that works, or figure out anything that works. I found a tut for doing what I am trying to do from a few year ago, but I can't even get past the amount of syntax errors that pop up in Dreamweaver!

    Looking at the tutorial, does that give anyone any ideas on how to do what I'm trying to do?

    EDIT: That tutorial I linked to contains the necessary documentation for logging into the CMS, but I am using the Log In found here on DevShed with a simple redirect if the credentials can not be verified.
  10. #6
  11. Web Developer/Musician
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Nov 2004
    Location
    Tennessee Mountains
    Posts
    2,408
    Rep Power
    1031
    Not a good idea to write directly to execuiable files from user input even if it's a page that is behind a login.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    Sounds like you're basically trying to reinvent the wiki.

    I agree with the last poster, you absolutely do not want your code writing to .php files. You'd be better off just having a directory full of indexed text files that you could include (after sanitizing the contents) in your .php files.

    Maybe I'm just not grasping the basics of your design, or the compelling reason why you want to do it the way you're doing it.

    Comments on this post

    • DoctorZeigler agrees : I've decided to go with the indexed text files! It works perfectly, thank you so much!!!
  14. #8
  15. No Profile Picture

    Join Date
    Aug 2013
    Location
    USA
    Posts
    4
    Rep Power
    0
    MeshCMS, Xaraya, Typo and Vanillablog are all capable of running free database. Some do use solite ut as that's flat file database built into PHP 5 I believe that counts. This Wikipedia page is a good place to get an idea of CMS require what database.
    ___________________
    PHP Application Development
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    America (But which one?)
    Posts
    43
    Rep Power
    2
    Originally Posted by admoore
    Maybe I'm just not grasping the basics of your design, or the compelling reason why you want to do it the way you're doing it.
    I just want to create an incredibly simple CMS. From the PHP that I linked to before, it looks very simple. If it worked... I have no need (or desire) to utilize MySQL as this is going to simply be an informative website with content that, at the most, will have minimal changes on a yearly basis. When those changes do arise, I want it to be simple for my user to change!

    With what I have, what is the best way to do this? With my current code I can submit the data, it loads index.php and displays the data, but if I refresh the page, it is no longer there. How can I get it to permanently save the information I input?

    -DZ
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    Originally Posted by DoctorZeigler
    I just want to create an incredibly simple CMS.
    "simple" can mean many things; a piece of code can be a simple implementation (no complex code involved) or a simple interface (complexity hidden in the code rather than exposed to the user). These two goal are often completely at odds. It sounds to me like you are aiming for both.

    From the PHP that I linked to before, it looks very simple. If it worked... I have no need (or desire) to utilize MySQL as this is going to simply be an informative website with content that, at the most, will have minimal changes on a yearly basis. When those changes do arise, I want it to be simple for my user to change!
    If you don't want to use a database, you're going to be operating in the filesystem, which creates a lot of potential security issues for PHP. You're going to have to take real care how you do this so that you don't inadvertently expose the whole filesystem to the world.

    With what I have, what is the best way to do this? With my current code I can submit the data, it loads index.php and displays the data, but if I refresh the page, it is no longer there. How can I get it to permanently save the information I input?

    -DZ
    Well, you have to write it to a file or a database. Since you don't want to use a database, you'll essentially have to reinvent the database on a filesystem level.

    There are many ways to do this; for instance, you could have a single text file holding all the editible snippets of code in some kind of configuration syntax. Your code would grab the correct snippet of HTML and insert it into the PHP file.

    Another way would be to put each snippet of editable code into its own text file. You can then "include" the contents of the appropriate text file in you php, and overwrite its contents with the admin interface.

    Desigining such a system is beyond the scope of a forum thread, so if you were hoping for a simple 1, 2, 3 here's-how-it's-done you'll probably be waiting a while. You might want to look at a file-based wiki like Dokuwiki and see how it works (Dokuwiki is open source and PHP).
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    America (But which one?)
    Posts
    43
    Rep Power
    2
    Thank you very much again for your help and your advice admoore!

    Obviously I'm no PHP pro, but I'm not understanding why this isn't easier, primarily because my code is 3/4 of the way there. I input the information on the admin page, and it posts to the index. From there, I need it to save permanently to the index. Can index.php not be the file the information I am submitting is saved to?

    The way I see it, if the data can be saved to a text file or a database, then shouldn't it have the ability to be saved to another PHP page?

    EDIT: While I would still love to know the answer to my question, I did some research on saving to txt files and then echoing the txt files in my index, and I got that to work perfectly! Thank you very much for suggesting this admoore!!!
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    Having code that rewrites itself (or other files containing code) is just not a real good idea from a security, stability, or maintainability standpoint. In programming we try to separate concerns, meaning data, logic, and presentation should ideally live in separate and loosely-connected spaces.

    Is it possible to do what you are asking to do? Probably. But it's a design you'll quickly regret, especially if the code is going live on the internet.

    Comments on this post

    • DoctorZeigler agrees : Thank you again for your reply admoore and thank you for explaining this!

IMN logo majestic logo threadwatch logo seochat tools logo