Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 5, 2009, 00:18   #1
awelch
SitePoint Member
 
Join Date: Nov 2009
Posts: 2
creating a simple cms with php and mysql

Hi,

I want to create a very simple cms containing:

page.php - a page template - that retrieves pageheading and content from the database based on the querystring pageID

I guess I need a database table containing pageID (pkey auto inc), page heading (ntext), content(ntext)

pagemanager.php - a page to display a list of pages existing in the database

insertpage.php - a page to insert a new page into the database, using FCKeditor to edit the text / upload files and images.

updatepage.php - a page to update pages.

Password protection for the admin side of things.

I'm new to php but I want to try to build this thing from the ground up rather than using something premade like drupal- i don't need the functionality. I'm making a very simple site and want to learn.

Can anyone lead me in the right direction for tutorials / advice on where to start concerning my project.

Thanks

Andy
awelch is offline   Reply With Quote
Old Nov 5, 2009, 00:29   #2
JamesColin
SitePoint Guru
 
JamesColin's Avatar
 
Join Date: May 2009
Posts: 611
Hi,
http://www.php-mysql-tutorial.com/wi...and-mysql.aspx
http://css-tricks.com/php-for-beginn...st-simple-cms/
http://www.devshed.com/c/a/PHP/Build...-in-PHP-MySQL/

Good luck, it's good to want to learn, personally I use Drupal and love it, but I've learnt a little PHP&MySQL before knowing about Drupal.
JamesColin is offline   Reply With Quote
Old Nov 5, 2009, 00:47   #3
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
Hi, awelch
You've got good aim.
It is a good way to learn things. You can have your CMS just in a few lines of code.

I'd suggest to start from insertpage.php, then proceed to pagemanager.php, then to updatepage.php (after you notice it is pretty same with insertpage.php, you most likely join em into one) and to the page.php at the end.

let's make insertpage.php of two parts: a form and a handler.
insertform.php will contain an html form and insertpage.php as simple code as this (if you choose MySQL):
PHP Code:

<?PHP
$table
="cms";

if(
$_SERVER['REQUEST_METHOD']=='POST') {
  
$heading=mysql_real_escape_string($_POST['heading']);
  
$content=mysql_real_escape_string($_POST['content']);
  
$query="INSERT INTO `$table` SET heading='$heading',$content='content'";
  
mysql_query($query) or trigger_error(mysql_error());
  
header("Location: http://".$_SERVER['HTTP_HOST']."/admin/pagemanager.php");
  exit;
}
?>
note /admin/pagemanager.php. i assume it will be place for it, and after you insert page, you must be relocated to manager page.
Shrapnel_N5 is online now   Reply With Quote
Old Nov 5, 2009, 00:49   #4
stonedeft
SitePoint Zealot
 
stonedeft's Avatar
 
Join Date: Aug 2009
Posts: 166
This is a good start rather than using open source CMS. I find it easier to do my own CMS than using open source as I have control over the flow of my codes. Besides it's very painful to dissect other people's codes. It took me almost 2 months to grasp core files of Wordpress and almost 5 months on Joomla. I have to admit most of my CMS functions comes from wordpress, Joomla and vbulletin

As a start you need to learn basic mysql queries , update, insert, delete, select. tizag.com is good place to learn basics, very straight forward tuts

You may also need a text editor. I love fckeditor www.ckeditor.com

and last a templating system. I always use btemplate more lightweight than smarty www.massassi.com/bTemplate/

Goodluck and happy coding.
stonedeft is offline   Reply With Quote
Old Nov 5, 2009, 04:58   #5
awelch
SitePoint Member
 
Join Date: Nov 2009
Posts: 2
I started to adapt the code from: css-tricks.com/php-for-beginners-building-your-first-simple-cms/

but a lot of people in the comments were complaining that the guy's code wasn't very good.

I understand how he has create a class with a bunch of functions to do different things, and I like that approach and could continue hopefully to extend it to include update, delete, (by pageID) etc etc.

I wantt to know if anyone has looked at the guy's code and would care to comment?

Is it worth me learning and adapting his code and method or would it be better to take a dif approach?

Thanks

Andy
awelch is offline   Reply With Quote
Old Nov 5, 2009, 05:07   #6
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
Yes it can be.
Any code can be worth to learn. In other hand, nobody's perfect. Any code can have mistakes. Even mine

This one is easy and short. Ok to learn. Just one thing i cannot agree is no use of templates in this code.
Password protection can be easily added.
Shrapnel_N5 is online now   Reply With Quote
Old Nov 5, 2009, 07:57   #7
elviajero
SitePoint Enthusiast
 
Join Date: Apr 2008
Location: Guatemala
Posts: 28
Quote:
Can anyone lead me in the right direction for tutorials / advice on where to start concerning my project.
Ok, you are doing this not only because you want to learn-practice php & Mysql... then as your goal is your CMS I suggest you to:
  • Plan things ahead to avoid future problems
  • Plan your cms around security
  • Make it portable and simple (you will need that in the future)
  • Focus on RECOVERY and MIGRATION. Many of us webmaster have faced servers down and migrations from one company to another, plan your cms around this, you will need it.
  • Keep in mind TEMPLATE features. Build your cms around this feature allowing you to use different templates with one click or modifying your prefs, instead of building it around a page that build itself making the requests.

I have made cms myself for my private use. Nothing to envy to the other cms!!! in fact mine are little apps with all the functionality without needing 3MB of code.

Good luck!!!
elviajero is offline   Reply With Quote
Old Nov 5, 2009, 08:03   #8
elviajero
SitePoint Enthusiast
 
Join Date: Apr 2008
Location: Guatemala
Posts: 28
one more thing, focus on not making it TOO PERSONAL, you might find a future buyer interested in your app.
elviajero is offline   Reply With Quote
Old Nov 5, 2009, 08:09   #9
chrisranjana
Web development Company
 
chrisranjana's Avatar
 
Join Date: Jan 2001
Location: chennai , tamil nadu , India
Posts: 696
Start with something small and slowly add on the features.
chrisranjana is offline   Reply With Quote
Old Nov 5, 2009, 09:05   #10
inverse.chi
SitePoint Addict
 
inverse.chi's Avatar
 
Join Date: May 2006
Location: Oxford, UK | Durham, UK
Posts: 243
I would recommend using a framework such as codeigniter to help speed up this process and use a MVC pattern to help split up your code.
inverse.chi is offline   Reply With Quote
Old Nov 5, 2009, 10:33   #11
macfoto
SitePoint Enthusiast
 
macfoto's Avatar
 
Join Date: Aug 2005
Location: British Columbia, Canada
Posts: 38
You might also want to check out the Sitepoint book "Build Your Own Database Driven Website Using PHP and MySQL". It covers how to use PHP, MySQL and how to begin making a CMS.
macfoto is offline   Reply With Quote
Old Nov 5, 2009, 18:51   #12
mkoenig
Jewish Juggernaut
 
mkoenig's Avatar
 
Join Date: Aug 2007
Posts: 1,147
Thats a great idea, i created my first cms about 5 years ago. Even if you don't make a successful one you will learn soo much. You can then take that code with you in the future, and improve upon it.
mkoenig is offline   Reply With Quote
Old Nov 5, 2009, 22:13   #13
AllyZen
SitePoint Member
 
Join Date: Jan 2007
Location: Victoria Australia
Posts: 1
This is so interesting.
I have always hand coded and just recently have been employed at a place that uses Joomla. I am not going to knock Joomla as it's great for what it is but I am used to starting a site from a blank textpad and adding only what I need as I go.
With Joomla its the other way around, you get too much code that you dont need and you spend ages sifting through it all.
If you want to modify any code you have to jump through a few hoops to find where it is or you might have to change stuff in more then one spot just to do a simple task. I spend more time in Joomla looking for stuff than I do anything else.
Anyway just hand coding what you want straight away is much easier.
AllyZen is offline   Reply With Quote
Old Nov 5, 2009, 22:59   #14
PHPycho
SitePoint Guru
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 637
If you want to take idea about CMS with the small footprints .
Definitely you can go with Frog CMS.
Which is small & lightweight.
PHPycho is online now   Reply With Quote
Old Nov 6, 2009, 06:20   #15
varul
SitePoint Enthusiast
 
Join Date: May 2008
Posts: 34
If you want to start your website by CMS software, use any one of the following as per your requirement.

DBPrism – first open source CMS based on Oracle XMLDB repository.
Flux CMS – XML/XSLT based, easy to use, extensible and suitable for developers to fill specific needs.
Freephpcms – easy to use, extensible and suitable for developers to fill specific needs.
Apache Lenya – Java/XML based CMS that comes with revision control, multi-site management, scheduling, and workflow.
Rubricks – CMS for Ruby on Rails fans, boasts simplicity and speed.
Clever Copy – A scalable website portal and news posting system.
Fundanemt – focused on usability and aimed at small and medium sized websites.
Dragonfly CMS – feature-rich open source content management system, based on PHP-Nuke 6.
Joomla - – popular, award-winning CMS that will help you build powerful online applications.
Silva – built on top of Zope, enables you to export to Word, stream media, store content as XML, and manage hierarchical and traditional websites.
YACS – build your online blogging communities.
ContentNOW – simple to use, flexible, multilanguage, modular CMS.
varul is offline   Reply With Quote
Old Nov 6, 2009, 06:27   #16
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
"based on PHP-Nuke" and "enables you to store content as XML" sounds like funeral music to me
Shrapnel_N5 is online now   Reply With Quote
Old Nov 6, 2009, 12:59   #17
Ryan Mortier
SitePoint Member
 
Ryan Mortier's Avatar
 
Join Date: Nov 2009
Location: Ontario, Canada
Posts: 5
I would recommend this book by Kevin Yank: Build Your Own Database Driven Website Using PHP & MySQL, 4th Edition

This book teaches you how to build a CMS from the ground up.

www dot sitepoint.com/books/phpmysql4/
Ryan Mortier is offline   Reply With Quote
Old Nov 6, 2009, 17:23   #18
rguy84
SitePoint Addict
 
Join Date: Sep 2005
Location: Seattle Area, WA
Posts: 248
I am going to start something like this also. One of the earlier replies talked about being security-minded. Can somebody maybe powst some tips what to consider/keywords to search for or links to articles that cover it?
rguy84 is offline   Reply With Quote
Old Nov 6, 2009, 17:49   #19
r937
SQL Consultant
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 30,261
Quote:
Originally Posted by rguy84 View Post
Can somebody maybe powst some tips what to consider/keywords to search for or links to articles that cover it?
1. http://en.wikipedia.org/wiki/Sql_injection
2. http://en.wikipedia.org/wiki/Cross-site_scripting
r937 is online now   Reply With Quote
Old Nov 6, 2009, 23:47   #20
artcoder
PeacefulParadox.com
 
Join Date: Aug 2005
Location: United State
Posts: 495
Instead of writing the CMS from scratch. I recommend using an open-source CMS. This can be Joomla, Wordpress, or Drupal. The article "Which CMS is best" talks about all three. I would go with either Joomla or Wordpress.
artcoder is offline   Reply With Quote
Old Nov 7, 2009, 00:45   #21
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
artcoder, it depends on goal
if one need to run their own site, I'll be first, who wote for ready-made CMS
if one wants to learn PHP language - writing CMS is very good practice dummy to train on

rguy84, just take in account that your first CMS won't be secure at all. It is ok. First things never be perfect. Many security issues learned only from own experience.
Shrapnel_N5 is online now   Reply With Quote
Old Nov 7, 2009, 01:16   #22
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
Anyway here is some security tips in brief, which I've already posted:
  • don't pass filenames over address string. or sanitize it
  • avoid SQL injection by following simple rules when build SQL query*
  • never use eval()
  • avoid XSS thing by stripping from user input all HTML tags
  • avoid CSRF thing by putting security code into any html form which uses POST method.
Shrapnel_N5 is online now   Reply With Quote
Old Nov 8, 2009, 22:29   #23
frank1
SitePoint Guru
 
frank1's Avatar
 
Join Date: Oct 2005
Posts: 975
ok u will find tons of tutorials for it
BUT
my simple advice...
just dont go for simple logic...
total procedural oriented simple php...10 lines codes....

make a mind frame to use best technique from the initial phases....like making single channel entry(use of functions),data santization,abstraction and making generic function and all...
if u start with that frame it will save lot of ur time later...
otherwise u will spent 6 months in simple php...and then relaize that i could have done in this way....and so on...
the simple things may block the innovation in initial phases....

and slowly moves to object oriented...with out which u wont be complete php programmer in php market(debatable but pratical truth...)
frank1 is offline   Reply With Quote
Old Nov 9, 2009, 06:45   #24
Ryan Mortier
SitePoint Member
 
Ryan Mortier's Avatar
 
Join Date: Nov 2009
Location: Ontario, Canada
Posts: 5
Quote:
Originally Posted by frank1 View Post
ok u will find tons of tutorials for it
BUT
my simple advice...
just dont go for simple logic...
total procedural oriented simple php...10 lines codes....

make a mind frame to use best technique from the initial phases....like making single channel entry(use of functions),data santization,abstraction and making generic function and all...
if u start with that frame it will save lot of ur time later...
otherwise u will spent 6 months in simple php...and then relaize that i could have done in this way....and so on...
the simple things may block the innovation in initial phases....

and slowly moves to object oriented...with out which u wont be complete php programmer in php market(debatable but pratical truth...)
Can you recommend any comparisons to what you are talking about. Sorry about my ignorance, I am quite new at PHP programming and have never programmed anything in my life, although I have this inevitable addiction towards programming so I've been teaching myself. Can you recommend any books on OOP with PHP?
Ryan Mortier is offline   Reply With Quote
Old Nov 9, 2009, 10:44   #25
frank1
SitePoint Guru
 
frank1's Avatar
 
Join Date: Oct 2005
Posts: 975
Quote:
Originally Posted by Ryan Mortier View Post
Can you recommend any comparisons to what you are talking about. Sorry about my ignorance, I am quite new at PHP programming and have never programmed anything in my life, although I have this inevitable addiction towards programming so I've been teaching myself. Can you recommend any books on OOP with PHP?
ok one simple comparision
few years ago i use to do
$data = mysql_real_escape_string ($_POST['data']);
//or any such function
now a days i do
$data=input_sanitizer($data,type);
and make a function and pass all input through single channel...
just an example and look simple but those different method have huge difference ,later having more than 100 of advantages....
u can add any santizing method(even later),u can make it more generic.....list goes on...

second
identify repeating codes and make it function file as soon as possible...like image_functions.php may be for validation as well ...and so on...

(ok i have reached around 100 such points...if i didnt wrote book i will definately post it somwhere online with examples...)

so things like these are often overlooked by intial staters and they just go for results....and later realaize...if i had known this ...ago....?...had i done this rather than this that time...and so on......
important thing to bear in mind...these are not step wise development...if one is capable...she can start using from any method ..points...it just limited to own personal thought,knowledge....

so start good habits from startup and think long term...

about oop book again,must of the php book i have found doesnt teach to make apps using oop php rather they teach u fundamentals of oop and how it is implemented in php....
so u can grab any book to get basics of oop...even c book may work....
then go to some framework straight away...if u become capable to do that it would save lots of ur time
for eg code igniter,cakephp....
coding in these framework can be termed as programming in oop php(ok not all....but definatley an oop php coder)
frank1 is offline   Reply With Quote
Reply

Bookmarks

Tags
cms

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 01:37.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved