Advice: building a non-database driven simple CMS in PHP [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a site which requires a very simple CMS - basically there's a block of text on the homepage that needs to be editable by the client. Their current hosting plan doesn't allow for a database, and including one will cost an extra $X a month which I think is unnecessary for such a basic system.
The site is currently built using Codeignitor. I'm planning to write the CMS part of it using either flat PHP or TXT files, are there alternative methods worth considering, and what are the pros/cons?

Okay, so further to this, I've opted for a custom flatfile system. I looked at a few of the recommended non DB CMS systems and they seem quite good - particularly this one which I later found: http://get-simple.info/
The reason for building my own is mainly due to the fact that the site is already on the Codeignitor Framework, and I don't want to rebuild it using a different one.
So my question now is - if my system is storing data in two txt files: one for userdata and one for site content, are there massive security issues if I set the sitecontent file permissions to RW? The site is quite small and I can't imagine anyone would want to hack it, but I'd still like to know if there are any major security implications.

Try http://www.opensourcecms.com/
example of some that might interest you
PivotX
pluck
razorCMS

cushyCMS
its ftp's into your hosting account, reads your html, and looks for tags that have a class="cushy" and makes those content feilds editable. its good forwhat your wanting.

I once solved this problem by simply putting markers in an HTML file, as HTML comments, and then had my PHP script parse the file and insert the desired text in between the markers. Done this way, you need no other files other than the PHP that handles the form submission from the CMS and a static HTML page.
In words, read the file into a string, explode() the string using the marker as the delimiter, modify the second (if you have a single editable section enclosed by the markers) array element to contain the new text submitted by the user, then implode the array back into the string, then write the string back as the complete file.

What about sqlite? it is just a file, no need to install anything? But if this is also not welcome, you could just keep the contents in txt files and have a php to read it, put to your template.

Related

PHP, Wordpress, and Databases - Oh My [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am building a new WP site and am pulling data from a secondary database and displaying it within WP pages. I am currently using the PHP Insert plugin and have successfully been able to display data on my site by typing in the PHP code right into the text part of the page.
I'm new to PHP and the backend of WP sites so I'm trying to figure out if I can reference other PHP files from within my code snippet or do I have to put all the PHP code in one place.
If I can reference other PHP files, then where do I put them from within my Wordpress environment?
Any guidance you can offer for me to learn this would be greatly appreciated OR if you have a recommendation for another way to organize my new PHP code to run on WP pages instead of a plugin. THANK YOU!
I have found that, except for the initial PHP code embedded in the WordPress page, it is easiest to maintain if all the other code resides elsewhere. WP sometimes does some funny things with loading pages due to showing parts of multiple posts on the home page, etc. so I have found it safest to use require_once() instead of require() or include(). I put the files in either a web accessible directory if they are designed to also run stand-alone, or in a non-web directory (generally preferred) if they should not be accessed except as part of your WP pages. Typically that would be required_once('/home/whatever/private/xyz.php') or require_once('/var/private/xyz.php') or something like that - the specifics will depend on whether you control the entire server or are working with what a shared hosting account gives you access to use. In some cases I distill it down to just a few parameters and the rest elsewhere - e.g.:
<?php
$id = 10;
$source = 'abc';
require_once('/home/whatever/private/xyz.php');
and let xyz.php do the rest as if it were running standalone with a couple of parameters passed in. The specifics will vary, but I've done it many times successfully.

MySQL queries via PHP to translate an HTML page in different languages. Good or bad? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm currently working on a website that was already created when I joined the project. I noticed that they use the MySQL database on the server to perform the web page translation. The HTML pages are very straight forward (boxes with selectable data, titles, checkboxes, etc.). The site is a control panel for a specific device; nothing fancy. Everywhere in the HTML there is this type of code to do the translations:
<?php translate("string to translate"); ?>
Where the translate() function in a query to MySQL and the PHP session contains the user language information.
For now, the site servers around 400 user (never simultaneously). I'm afraid this is not a scalable solution and as soon as the site will have a decent amount of traffic, it will run like crap.
Is my assumption bad? Should I go with different HTML files for each language (like most web sites, IMO)?
Thanks!
Your solution seems to be hardly scalable and not optimal in a sense that the number of queries you get will grow significantly faster than number of users.
"Should I go with different HTML files for each language (like most web sites, IMO)", no, don't write HTML for each language, that's an old school way to do it and nowadays all sites user templates - one HTML with translatable variables instead of text.
My proposition would be to use one of the frameworks out there, for example Zend or Symfony that have efficient translation mechanisms ready to use out of the box. All your translations would be in a single language file like en_US.po or lt_LT.po and you could edit them using Poedit software.
If you don't want to use framework and want a simpler solution - create a php file for each language with variables containing text, e.g.
en_US.php
$translation['page_title'] = 'My cool company title';
$translation['menu_title'] = 'Navigation';
lt_LT.php
$translation['page_title'] = 'Mano kompanija'; // Lithuanian translation
$translation['menu_title'] = 'Navigacija'; // Lithuanian translation
Then include the necessary file before you load HTML and use those variables in the template:
index.php
<?php
// Very simple approach to insert the necessary translation file, could be optimized/tuned
if ($_GET['language'] == 'en_US'){
require 'en_us.php'
}
else if ($_GET['language'] == 'lt_LT'){
require 'lt_LT.php'
}
?>
<html>
<title><?= $translation['page_title']; ?></title>
<body>
<menu><?= $translation['menu_title']; ?></menu>
</body>
</html>
Hope this helps. Let me know if you have any questions.
You could use in memory storage for every languages, and then load data from memory.
Check at Redis, with it, you can store data as key => value.
Then you could store : "fr.my_key = 'ma clé'", and so on for everything, then store the prefix ('fr' here), in the session.
This would be much faster than your actual solution, consuming less resources, and still way better than creating x templates and reading files on the file system.
Plus I doubt this would require a lot of RAM. Maybe 10 MB if your site is very very big.

How big can CMS database be? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am planing to build a simple CMS (with PHP) for my own educational needs and I ran into a problem with design as I have never encountered this in any book or tutorial.
If I wanted to let used mess around the colors for example. How do I do that? The only idea I had was make a database with basically all such a options and then echo them to the site as normal CSS. But thet would mean it would load from DB every single time someone visits the webasite. It seems to me like it could overload the website. But again, I have never encountered such a problem. Or is there a way of doing this much more easily?
Thanks for every answer!
EDIT:
I would like to create a system that enables user to change css via CMS. For example background color, drop-down menu colors, text sizes, fonts and a lot of other stuff handeled by CSS. Simple customization.
So I was asking 2 questions.
How? What system should I use? No book/tutorial I read never covered editing CSS files using PHP so I have no idea how to do that. Or maybe there are better ways of doing it?
I had idea how I would store all customisable data. In database I wanted to know how big it can be and whether it would be a problem when posibly tens or maybe even houndreds of variables would be loading to the site.
EDIT2:
And btw I never worked with Wordpress or other CMS and I kind of expected that options like what I am looking for are present there, is that true? In my mind such a feature is essential for user inexperienced with computers. But from what I understand from link provided by Sam (http://css-tricks.com/css-variables-with-php/), it's not common. It's actually quite complicated thing and might harm performance of the website.
I hope I made my question clear now.
I know this has tons of downvotes, but you can cache your database queries. You can also mimic a CSS file using the header type in PHP. See http://css-tricks.com/css-variables-with-php/
This will allow the browser to cache the CSS file that was generated by PHP & MySQL. This means the database will only be called when the cache expires.
In terms of size you will never reach a limit with what you are describing.
Update
These sort of features are a bit unorthodox, using a cached version of the generated CSS file is basically mandatory.
What you can do is include a text editor within the CMS to edit the CSS file, each user can have their own CSS file that overrides the default one if changed. By letting them edit it directly they can change the layout themselves. You can even limit them to only changing colours / font-sizes etc.

Why would you host html pages instead of php? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
If I'm hosting a website on a server that has PHP, would I ever need to host a .html file on it? PHP files can have raw HTML code inside of them as well as the added benefit of being able to inject PHP code, so isn't PHP a more inclusive language?
Serving HTML is generally a lot easier for the webserver than serving a page that has to be run through the PHP interpreter.
This can have huge benefits on high-traffic sites. For example, the Obama campaign ran their fundraising platform with a lot of static HTML for that reason.
it always can be situation that you would need to add e.g. maintenance page in pure html
It's not a question of whether you can simply make everything "a PHP file" but rather a question of whether any given file needs to be PHP. If a file contains only static content, there's no need for any server-side processing. So in such cases it would make more sense to make it an HTML file.
Don't look for a tool that covers all cases, look for the right tool for each case.
I read that it is recommended to have <?php flush(); ?> between </head> and <body>. I would assume that this should apply to every webpage, there really isn't a solid reason as to why you would only use HTML.
I agree with ceejayoz, but if that's not a problem for you, then using PHP is great.
It depends on your purpose. If your page uses PHP then the file extension needs to end in .php. If you don't have any PHP then you can just save the page with a .html file extension. A major difference is that PHP is processed on the server side. Meaning the user(client) will not see your PHP code if he views the source, he'll see what was processed from the server in the form of HTML.
One advantage of using .php files over HTML (in this trivial case) is that, you can wrap up all your footer files(if the are the same) or any redundant files, like sidebar, advertisingand just include them in your other files, instead of having to create/manage individual files later, So, you can just open one footer.php file and make as many changes as you want without wasting any time.
Your basic understanding is correct. You can absolutely have a .php file that has only HTML in it and given a simple page and a simple site there would be little difference.
However, the PHP preprocessor adds a bit of overhead to check for PHP code in the file. In most cases this is insignificant, but on a highly optimized site you probably would not want the pages to be processed for nothing.
I wouldn't say that PHP is a more inclusive language though, HTML and PHP are two different things. In many cases (but by no means all) PHP generates HTML. It's just that the resulting HTML from a PHP script that has no PHP tags in it would most likely be the same as it would be for an html file. Although it is likely that HTTP Response Headers would be different and there are other things outside of the file content itself that could be slightlu

How to organize or use pre-exsisting html into a new php application? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Looking for ideas on how to go about working with a large set of .html files (50,000+) that are preexisting.
What I am trying to accomplish is to be able to keep the same hierarchy, links etc... but add content to them via php or whatever etc..
To be able to organize or route them into a php application or my own cms. I have been thinking ways to do this and come up with a few ideas but hoping to get some feedback from some pros.
I really only need to create something that will get the data once and add it to a cms that I develop. I have a script that I wrote to be able to index and search etc.. but how to go about using the contents and adding to them while keeping structure has me swinging a little. Any thoughts?
UPDATE: I found some tips that made this easier for me as well
Use a .htacess file and ad:
AddType application/x-httpd-php .html .htm
Then I can add includes into those files, I am note sure where to put this in the config file yet but will update when I know.
If you were to use a CMS like Wordpress, assuming your content follows some sort of regular structure, you could recreate the HTML frame as templates and then write a script that parses each HTML file and creates a post based on criteria like the HTML file name.
You can even match the file name by setting the slug on post creation, though you'll need a server rewrite rule to drop the .htm(l) if you intend to keep all the backlinks to the site.
I'm oversimplifying of course, as with 50,000+ files it isn't a trivial job to move all the data.
Perhaps automate it using something like this: http://wordpress.org/extend/plugins/import-html-pages/
The way I would go about it is to keep the html in a function which you require. Separate them logically as:
function output_html_one($link_here, $or_link_there...) {...}
function output_html_two($other_links...) {...}
When you want to output them with the files you have, just call the function, and it will be sent out. I am sure others will give you preferences. This allows you to give them access to variables through arguments, which is a downside, but it keep everything organized and provides some clarity as you can separate the raw html from the logic in your code. I am very curious to see what others say.
EDIT: I added $user inside of html_header so its clearer. For example, lets say you might want to check if a user is logged in. This gives you a way to tailor your html. Then you go to the files which contains this, you can jump in and out of the php tags in order to add dynamic content.

Categories