Results 1 to 10 of 10
-
17th Jul 2010, 11:30 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.com[PHP] Discussion (System Building)
This thread is mainly to try and help guide the lost sheep in the right direction when it comes to PHP and building systems securely.
Now you all probably think that I'm real good at PHP but I'm not, what im good at is understanding architecture.
What i mean by architecture is summarized in these key points
- Functional/logic view
- Code/module view
- Development/structural view
- Concurrency/process/thread view
- Physical/deployment view
- User action/feedback view
- Data view
From this list you will see that an application is more that an if statement here and and else statement there, its about writing code in a way that it can be used for multiple purposes and have a more abstract approach to things.
now if i refer to you as a noob do not take it personally if you write code at a lower level, theres still time to save you, but noobs are everywhere and they create sites that are error prone and unsecured and unstable.
this is why everyday somebody in this forum posts a topic regarding asome shitty php code and saying help me fix it, as you notice us programmers such as jayfella hyperz and me get annoyed because its hard to fix a peice of code thats written poorly.
so firstly im going to explain how a noob would create a small website and how it can be dramatically changed to a more stable and less error prone system.
----
Site Name: My Mini Blog
Site Desc: Small blog
Created By: A Noob
the noob would firstly start placing all his html into into index.php with some sample posts in there aswell, so he can see where he wants his code.
then after he has the design how he wants it it will cut out the html posts and place some php tags there, connect to the database and start running queries
then he will create another page call addpost.php and do the exact same as in the first page
not this is not smart atall, this means that if he wants to make a change to lets say the database he would have to go throughout each file and do lots of edits.
ok so lets talk about how a professional programmer would accomplish the same thing!
he would create a set of files that store configurations such as datbase credentials, error settings, security, options etc.
he would then create a small database layer,security layer,error layer, etc etc
this would give him the flexibility to make 1 change to his database layer and that would change for the whole application.
For example
PHP Code:class MySql extends mysqli
{
public function __construct($host,$user,$pass,$db)
{
parent::__construct($host,$user,$pass,$db);
}
}
ok so lets say that you want to have a prefic for your tables so you can do
Code:SELECT * FROM #__users WHERE userid = 1
PHP Code:public function query($query, $result_mode = MYSQLI_STORE_RESULT)
{
$query= str_replace("#__","myPrefix_",$query);
return parent::query($query,$result_mode);
}
if you have any questions about building a system like this and how to start it, just ask your questions and ill try and help
also do not be afraid of making mistakes, if you kept doing the way you know is wrong but it works, then you will never ever learn.litewarez Reviewed by litewarez on . [PHP] Discussion (System Building) This thread is mainly to try and help guide the lost sheep in the right direction when it comes to PHP and building systems securely. Now you all probably think that I'm real good at PHP but I'm not, what im good at is understanding architecture. What i mean by architecture is summarized in these key points Functional/logic view Code/module view Development/structural view Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
18th Jul 2010, 04:02 PM #2Member
Nice post..
Now please guide me in this..
I have written some code in php , which uses cURL and gets information from an API in json format, then I am decoding it , and storing it in variables.., when I need to show the value of a variable to the users , I am embedding php tags in html, which I think is not good..so do you suggest me to use some kind of template engine ??
I want to avoid smarty , but rather make a small template engine myself..
ThanksCoding Horror Fan
I don't read PM's frequently .
-
19th Jul 2010, 06:28 AM #3Member
What I do instead of building a whole framework for sites I code, I use the phpBB3 code as a framework, because I like how it works, with support for utf8, multibyte and other things. Also, using their DBAL is great for multiple types of database systems.
EDIT: Just noticed your example, why don't you use PDO instead of creating a whole new class?
-
19th Jul 2010, 09:47 AM #4MemberWebsite's:
Doxsters.netHm nice post, It got me thinking.
Also, I'm thinking of learning OOP PHP, do you have any tips? I've never done OOP before
Need a Designer/Web Developer? Click Me
MSN: PM me for it.
Email(Preferred):timtamboy63@gmail.com
"Power Corrupts. Absolute Power Corrupts Absolutely"
-
19th Jul 2010, 09:58 AM #5Retired NinJaWebsite's:
loledhard.com
-
19th Jul 2010, 10:45 AM #6MemberWebsite's:
Doxsters.netI'm sure i'll manage with the internet
Need a Designer/Web Developer? Click Me
MSN: PM me for it.
Email(Preferred):timtamboy63@gmail.com
"Power Corrupts. Absolute Power Corrupts Absolutely"
-
19th Jul 2010, 10:50 AM #7Retired NinJaWebsite's:
loledhard.com^
May be this would help u
http://www.gillius.org/ooptut/index.htm
You don't hate Justin bieber.You hate the fact you ain't Justin Bieber!
-
19th Jul 2010, 01:16 PM #8OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comOk some of you have asked for an example for a template engine, well ive already done that.
http://www.besthostingforums.com/showthread.php?t=38800
AS for the example of curl here is a little one:
PHP Code:Class MyCurl
{
private $handler = null; //Used to hold the reource from curl_init();
private $url = null; //Hold the url were fetfching
private $options = array();
private $data = '';
public function __construct($url = false) //used when you create the object like $var = new Curl
{
$this->seturl($url);
}
public function SetUrl($url)
{
$this->url = $url;
}
public function SetOpt($name,$value)
{
if(is_array($name))
{
foreach($name as $key => $value)
{
$this->SetOpt($name,$value);
}
return;
}
$this->options[$name] = $key;
}
public function Init()
{
$this->handler = curl_init($this->url);
curl_setopt_array($this->handler ,$this->options);
$this->data = curl_exec($this->handler);
}
public function GetData()
{
return $this->data;
}
//Here just create your own methods such as
}
$MyCurl = new MyCurl('google.com');
$myCurl->SetOpt(CURLOPT_PORT,80);
$MyCurl->Init(); //Send the request
$data = $MyCurl->GetData();
AS for the reusable code section in my First Post, all you have to do is add a function to set all the variables within the class back to there originals, you can then just use SetUrl to start a new request. and so on.Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
19th Jul 2010, 02:25 PM #9Member
thanks , that really helped me to understand some new concepts..and I will use your template system
Coding Horror Fan
I don't read PM's frequently .
-
19th Jul 2010, 02:32 PM #10OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comNo Problem.
Remember Desiboy, The way i designed the template system is minimal but abstract.
So if you implemented the template system to one of your projects.
You can always create methods within the ViewLoader to suite your needs
For example:
Code:public function CreateLink($url,$title) { return sprintf('<a href=http://4.hidemyass.com//browse.php?u=Oi8vd3d3LndqdW5jdGlvbi5jb20vJnF1b3Q7JSQxcyZxdW90Ow%3D%3D&b=1 title="%$2s">%$2s</a>',$url,$title); }
Code:<b><?php echo $this->CreateUrl('http://mysite.com','Home'); ?></b>
And about 7x faster then Smarty.Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
PHP PDO login system, user class. Also Includes a theming system {Source}
By xifyhosting in forum Web Development AreaReplies: 3Last Post: 29th Aug 2012, 02:33 AM -
Free Report : List Building System
By errabbaa in forum Webmasters, Money MakingReplies: 2Last Post: 6th Jun 2012, 01:25 PM -
The FartMan is in the building...
By The FartMan in forum IntroductionsReplies: 3Last Post: 25th Jun 2011, 04:04 PM -
Building R/C Car
By sniper in forum General DiscussionReplies: 6Last Post: 11th Jul 2010, 09:19 PM -
building your pr-
By clarksta in forum Webmaster DiscussionReplies: 5Last Post: 17th Nov 2008, 04:11 PM
themaPoster - post to forums and...
Version 5.38 released. Open older version (or...