Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-25-2012, 08:19 PM   PM User | #1
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
If you built your own simple CMS...

I've been taking on online courses to learn PHP and right now the project is to build a simple CMS. I get that and I know the basics about managing tables and databases, but what if I wanted to 'package' that CMS for other people? How do you transfer a cms with its tables and everything packaged and ready to go? Is this simple to do? Thanks!
KULP is offline   Reply With Quote
Old 12-25-2012, 09:17 PM   PM User | #2
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
You can use files to run SQL. I remember once I used another person's code that required some MySQL tables, and it came packaged with a .sql file. All I had to do was go into phpMyAdmin and select "upload file", or "create from file", or something along those lines (It was a while ago!). I believe it's just normal SQL queries in the file. There are other options as well, like including a normal web-page file and directing a first-time view of it to create the database. I think if you have so far been creating your database structure with the visual interface provided, you should begin working on creating these things with SQL queries. SQL in some manner seems to be the best way to package table setups and other database structure stuff. Not that I have had much experiance with trying to package my stuff.

Other things you might want to become aware of when making code to share is server environment issues. Dealing with PHP you might want to be checking the status of each feature you are using against the documentation. A lot of changes have been made per version 5.3 in particular it seems, but there are still many hosts that are running pre 5.3 PHP setups. Either avoiding the shiny new toys, or being aware of (and broadcasting) the minimum version your shared code will work on can go a long way to making it more professional (and 'bug'-free for other people). The same might be said about checking your php.ini settings, and being aware of any non-defaults with that.
Custard7A is offline   Reply With Quote
Old 12-25-2012, 11:50 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Bah, Custard you're still making that harder than it needs to be. Many people don't even know how to use phpmyadmin.

Run this in phpmyadmin to test and then use it in your setup scripts to create the tables:
show create table <tablename>

This will show you the SQL to create the new table with the same structure. At this point you can via your php, insert your first rows of data as part of the setup - eg an admin user.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-26-2012, 03:45 AM   PM User | #4
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
One time I wanted to make my scripts smart, so that if they tables didn't exist they would be created on the spot. I never did it, but that might be very nice for running script out of the box or switching databases. That would leave a band-width footprint that would do nothing 99% of the time, I suppose is the drawback, but throw in autoloading and it doesn't seem as horrible.
Custard7A is offline   Reply With Quote
Old 12-26-2012, 06:07 PM   PM User | #5
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Thanks y'all, that helps a lot.

So lets say I create a set up page, titled setup.php and I tell people that are using my cms to go to root.com/setup.php and this page makes the tables and inputs initial data and sets up maybe even the admin user/pass. Then I could use the unlink("setup.php"); function to delete the setup file at the end of setup. Would this be a good way to do this?

Last edited by KULP; 12-26-2012 at 06:22 PM..
KULP is offline   Reply With Quote
Old 12-26-2012, 06:28 PM   PM User | #6
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by KULP View Post
Then I could use the unlink("setup.php"); function to delete the setup file at the end of setup. Would this be a good way to do this?
Your script won't be able to delete itself. Your best bet would be to redirect users to the main page with a parameter in the url (eg setup=1) which tells the main script it can delete the setup script. That or you get the users to delete it manually via FTP.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-26-2012, 06:52 PM   PM User | #7
KULP
Regular Coder

 
Join Date: Mar 2012
Posts: 166
Thanks: 5
Thanked 11 Times in 11 Posts
KULP is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
Your script won't be able to delete itself. Your best bet would be to redirect users to the main page with a parameter in the url (eg setup=1) which tells the main script it can delete the setup script. That or you get the users to delete it manually via FTP.
Ah, so a file can't delete itself, you have to have another file delete it. Alright well that sounds simple enough! Safe I assume as well? Building a CMS is kind of fun... >
KULP is offline   Reply With Quote
Old 12-26-2012, 07:03 PM   PM User | #8
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by KULP View Post
Ah, so a file can't delete itself, you have to have another file delete it. Alright well that sounds simple enough! Safe I assume as well? Building a CMS is kind of fun... >
Suppose they need to run set-up again? Might it be preferable to just rename the file? Or perhaps the set-up sequence could check for the existence of a table to know that it has already been run? In which case, the user would need to delete the database or table(s) to re-run the set-up sequence.

Just a suggestion
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-26-2012, 07:07 PM   PM User | #9
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by AndrewGSW View Post
Suppose they need to run set-up again? Might it be preferable to just rename the file? Or perhaps the set-up sequence could check for the existence of a table to know that it has already been run? In which case, the user would need to delete the database or table(s) to re-run the set-up sequence.

Just a suggestion
No you never leave setup files in place for attackers to misuse. NEVER. This is the very reason forums like PHPBB refuse to operate if the install directory is still in place. They effectively shut down to prevent abuse of the NON PASSWORD PROTECTED setup script.

Always delete the setup script because otherwise you're going to come a cropper when someone has abused it and setup their own stuff on your server. It's also too easy for the site owner to re-use it and screw things up. Setup once and leave it be.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-27-2012, 06:17 AM   PM User | #10
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
That's another good point for when you're sharing code. Bad people have full access too, so they can download the scripts and look for any point of weakness. You have to be careful that you're not putting everyone who might use it at risk.
Custard7A is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:48 AM.


Advertisement
Log in to turn off these ads.