Monday, 11 April 2016
'Paypal hacked!!' Avoid Getting Hacked | Protection against Keyloggers
Keylogger have also been popular, still are!
I don't know how many of you are aware of this but I'll go ahead and share it with you all. First things first, if you've been infected by a keylogger program your actions will be recorded, hacker usually receives the logs by email through a little SMTP or similar program that is usually setup in keylogger during the development process. In other words, typing your password into input password field will be recorded and stored into a file in usually 'appdata' or 'temp' folder. Which then is periodically sent to hacker's email address. Next thing you know your passwords have been changed and Paypal money transferred. Being infected and changing passwords won't do any good since keystrokes are will still be recoded.
One way to stay somewhat safe against this malicious act is to encrypt your keystrokes. Imaging your password is '123456789', if it's encrypted it will be completely converted to a encrypted characters, making hacker almost impossible to revert it. So when they get email with passwords, they will be unable to read it.
Here's an example of '123456789' text hashed using SHA-256.
15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225
I'm on Linux right now, but when I was on windows I used to use a program called https://www.qfxsoftware.com/
Those who're keen to test it out you can setup any keylogger on your own PC and and check the data whether it's readable.
Monday, 14 March 2016
How to become a web developer complete guide
You ask how do I become a web developer? Lets get straight to it, shall we? please don't be discourage if there's things you don't know or heard about.
Noob Level:
- HTML 5
- CSS 3
- Javascript
Learn just the basics. Should be able to create basics styling, make HMTL elements. Know few thing about Javascript like changing element ID using it or its color, know what a variable is etc.. Not much just a few things. Don't stress too much. This phase is about having fun! creating random stuff, show off to your buddies and going crazy!
Intermediate Level:
- HTML 5
- CSS 3
- Javascript/jQuery
- How internet works
- How servers work
- Setting up a domain and DNS
- Buying a Hosting
- FTP
- PHP
- DOM
Should be able to create simple websites. Validate user input, know how functions work, conditions, loops. Should also be able to connect to database and insert or retrieve data. Have good understanding of what a client side language can and can not do. Also understand what DOM Document object model is.. This phrase is about building foundation and have good understanding of technologies, don't necessarily need to be that good but good enough to look at a websites code and not be too afraid to mess around.
Expert Level(Front end developer):
- HTML 5(Expert)
- CSS 3(Expert)
- Javascript(Expert)
- How internet works(Must know)
- How servers work(Must know but don't waste your time too much on it)
- Setting up a domain and DNS(Must know)
- Buying a Hosting(Must know)
- FTP(Must know. You'll mainly using program like filezilla)
- PHP(Basics)
- DOM(Must know)
- JSON/XML(Don't stress too much)
- Git(Must know)
- Terminal/CLI(Don't stress too much but know a few thing)
- Photoshop(Expert)
- Wordpress(Good to know, should be able to design layouts)
- Atleast one front end framework, for example jQuery.(Must know)
- Bootstrap(Must know)
- At-least one open source editing program(Must know. Not every company will have budget for Photoshop)
- Sense of layouts/User Experience and colors(Expert)
- Graphics designing skills(Expert. Should be able to design stuff from scratch or take existing work and incorporate it into pre existing graphics)
This is for someone who wants to get into front end. This are the thing you'll be messing with everyday. This indeed is alot of stuff, but as far as it's fun to learn there should be no issue. Just keep grinding and working on new stuff. This phase is were you will get better at stuff you learn. For example, you won't be very good understanding XML/JSON code that server might throw at you, but you will eventually learn ways to make things easier for yourself.
Expert Level(Back end developer)
- AJAX(Be okay)
- How internet works(Solid understanding required)
- How servers work(Solid understanding required)
- How DNS work(Solid understanding required)
- Setting up a domain and DNS(Must know)
- Buying a Hosting(Must know
- Should be able to choose hosting dependong on your needs. See whether they will allow certain version of PHP, will enable modules. Data usage limits, uptime, support etc etc..)
- FTP(Must know using both GUI and CLI)
- OOP(Must know Object orignted programming - style of programming heavily used)
- Web application security(Be very good)
- PHP(Be very good)
- Atleast one backend framework(Be okay. For exmaple, Laravel, codeigniter etc..)
- SQL(Be good language itself and also using extensions like sql, sqli, pdo).
- API(Must know Application programming interface)
- Apache(Must know Should be able to install on fresh server and get necessary modules. Should also know how to use modules like mod_rewrite)
- Little bit of server administration, like changing permissions. Installing software necessary etc..(Be okay)
- HTML 5(Not as good as front end developer)
- CSS 3(Not as good as front end developer)
- Javascript/jQuery(Not as good as front end developer)
- How TCP/IP work(Be okay)
- Other server side language(Learn if required)
- Regex(Be okay. You will be using this alot when messing with apache modules)
- DOM(Be okay)
- JSON/XML(Be okay)
- Wordpress(Be okay)
- Git(Be okay)
- Understanding of HTTP(Be okay. Headers, requests responses)
- Terminal/CLI(Be okay)
- SSH(Be okay. Secure shell to access your server. Could use PuTTy too)
- Linux(Be okay. any one Distro)
- Photoshop(Be okay).
Expert doesn't mean you're done. You're still in process of learning and as you go you'll learn new stuff every day. At this stage you're just sharpening your skills.
Remember, web development is a very complex field and is an ongoing process. You're never too good. For example, you could learn how to build and fix PC and start your own business, however when it comes to website development it's big mixture of skills you need to be good at, just one thing doesn't cut it.
Last buy not least, always remember that people pay for solutions not skills.
Noob Level:
- HTML 5
- CSS 3
- Javascript
Learn just the basics. Should be able to create basics styling, make HMTL elements. Know few thing about Javascript like changing element ID using it or its color, know what a variable is etc.. Not much just a few things. Don't stress too much. This phase is about having fun! creating random stuff, show off to your buddies and going crazy!
Intermediate Level:
- HTML 5
- CSS 3
- Javascript/jQuery
- How internet works
- How servers work
- Setting up a domain and DNS
- Buying a Hosting
- FTP
- PHP
- DOM
Should be able to create simple websites. Validate user input, know how functions work, conditions, loops. Should also be able to connect to database and insert or retrieve data. Have good understanding of what a client side language can and can not do. Also understand what DOM Document object model is.. This phrase is about building foundation and have good understanding of technologies, don't necessarily need to be that good but good enough to look at a websites code and not be too afraid to mess around.
Expert Level(Front end developer):
- HTML 5(Expert)
- CSS 3(Expert)
- Javascript(Expert)
- How internet works(Must know)
- How servers work(Must know but don't waste your time too much on it)
- Setting up a domain and DNS(Must know)
- Buying a Hosting(Must know)
- FTP(Must know. You'll mainly using program like filezilla)
- PHP(Basics)
- DOM(Must know)
- JSON/XML(Don't stress too much)
- Git(Must know)
- Terminal/CLI(Don't stress too much but know a few thing)
- Photoshop(Expert)
- Wordpress(Good to know, should be able to design layouts)
- Atleast one front end framework, for example jQuery.(Must know)
- Bootstrap(Must know)
- At-least one open source editing program(Must know. Not every company will have budget for Photoshop)
- Sense of layouts/User Experience and colors(Expert)
- Graphics designing skills(Expert. Should be able to design stuff from scratch or take existing work and incorporate it into pre existing graphics)
This is for someone who wants to get into front end. This are the thing you'll be messing with everyday. This indeed is alot of stuff, but as far as it's fun to learn there should be no issue. Just keep grinding and working on new stuff. This phase is were you will get better at stuff you learn. For example, you won't be very good understanding XML/JSON code that server might throw at you, but you will eventually learn ways to make things easier for yourself.
Expert Level(Back end developer)
- AJAX(Be okay)
- How internet works(Solid understanding required)
- How servers work(Solid understanding required)
- How DNS work(Solid understanding required)
- Setting up a domain and DNS(Must know)
- Buying a Hosting(Must know
- Should be able to choose hosting dependong on your needs. See whether they will allow certain version of PHP, will enable modules. Data usage limits, uptime, support etc etc..)
- FTP(Must know using both GUI and CLI)
- OOP(Must know Object orignted programming - style of programming heavily used)
- Web application security(Be very good)
- PHP(Be very good)
- Atleast one backend framework(Be okay. For exmaple, Laravel, codeigniter etc..)
- SQL(Be good language itself and also using extensions like sql, sqli, pdo).
- API(Must know Application programming interface)
- Apache(Must know Should be able to install on fresh server and get necessary modules. Should also know how to use modules like mod_rewrite)
- Little bit of server administration, like changing permissions. Installing software necessary etc..(Be okay)
- HTML 5(Not as good as front end developer)
- CSS 3(Not as good as front end developer)
- Javascript/jQuery(Not as good as front end developer)
- How TCP/IP work(Be okay)
- Other server side language(Learn if required)
- Regex(Be okay. You will be using this alot when messing with apache modules)
- DOM(Be okay)
- JSON/XML(Be okay)
- Wordpress(Be okay)
- Git(Be okay)
- Understanding of HTTP(Be okay. Headers, requests responses)
- Terminal/CLI(Be okay)
- SSH(Be okay. Secure shell to access your server. Could use PuTTy too)
- Linux(Be okay. any one Distro)
- Photoshop(Be okay).
Expert doesn't mean you're done. You're still in process of learning and as you go you'll learn new stuff every day. At this stage you're just sharpening your skills.
Remember, web development is a very complex field and is an ongoing process. You're never too good. For example, you could learn how to build and fix PC and start your own business, however when it comes to website development it's big mixture of skills you need to be good at, just one thing doesn't cut it.
Last buy not least, always remember that people pay for solutions not skills.
Ip hacked! what can they do with it? How to prevent it in future?
Fact than most can't do shit after obtaining IP address is hilarious really.
If you don't already know about this way of obtaining peoples IP you're still living in stone age, and should really learn not to click any link your online buddies send you. Actually your buddy is just wannabe hacker who wanna get your IP to scare you. So please click on the link he sends you next time to not spoil their dreams of becoming next Adrian lamo.
Thanks.
![[IMG]](http://s2.quickmeme.com/img/9c/9ccb6a3aa78171a11e807ccefd5949d6100fb3b18d3db441b85576156908b4be.jpg)
Proceeding..
I'm talking about all known http://whatstheirip.com/ Basically they would put email on this site and click "get link".
![[IMG]](http://i.imgur.com/IVbFpLZ.png)
After that redirection to different page happens where it provided with link to get other peoples IP.
![[IMG]](http://i.imgur.com/Dn7KH67.png)
Generally these people who're trying to get IP will email the link to you saying, "This is so sad..!!!".. as if your life has been any different. Some will go as far as masking the link and make it appear like its legit site. Fucking. Bastards.
![[IMG]](https://s-media-cache-ak0.pinimg.com/564x/3a/83/d4/3a83d450697f9b743dd1999f3bc5142a.jpg)
Friendship whent down the drain after couple months.. and guess what your friend has? dat IP address!!
![[IMG]](http://remycarreiro.com/wp-content/uploads/2013/03/slapface-5000.jpg)
"You pussy you scared, I can hear your heart beat" Yeah 50 cent rocks! But really what can he really do with it? Nothing. Most average Joe cant do shit except for pinging your address with 64 bits haha lol'd.
![[IMG]](http://i.imgur.com/did9bXG.png)
But wait apparently your friend has taken a networking course called CCNA and probably knows a shit or two.. what's the most he can do? He can go buy a "Booter" and lit your ass up, not literally. He can probably take your cute internet connection down and null a port. So you cant visit facebook no more.
![[IMG]](http://cdn.meme.am/instances/60998065.jpg)
What else can he do?
- He can DOX you, using your IP address to filter information.
- He can search old hacked databases for your IP address and hack for email and shit if that site had not hashed data.
- He can post on online forums to DDOS that IP.
- He can do some port scanning shit.
How do I prevent all this?
- Don't signup on BS sites.
- Don't click shit links.
- Don't talk to strangers.
- Don't install bullshit.
- Don't ever use common sense. jk. But seriously avoid using common sense at all costs. It's expensive.
If you don't already know about this way of obtaining peoples IP you're still living in stone age, and should really learn not to click any link your online buddies send you. Actually your buddy is just wannabe hacker who wanna get your IP to scare you. So please click on the link he sends you next time to not spoil their dreams of becoming next Adrian lamo.
Thanks.![[IMG]](http://s2.quickmeme.com/img/9c/9ccb6a3aa78171a11e807ccefd5949d6100fb3b18d3db441b85576156908b4be.jpg)
Proceeding..
I'm talking about all known http://whatstheirip.com/ Basically they would put email on this site and click "get link".
![[IMG]](http://i.imgur.com/IVbFpLZ.png)
After that redirection to different page happens where it provided with link to get other peoples IP.
![[IMG]](http://i.imgur.com/Dn7KH67.png)
Generally these people who're trying to get IP will email the link to you saying, "This is so sad..!!!".. as if your life has been any different. Some will go as far as masking the link and make it appear like its legit site. Fucking. Bastards.
![[IMG]](https://s-media-cache-ak0.pinimg.com/564x/3a/83/d4/3a83d450697f9b743dd1999f3bc5142a.jpg)
Friendship whent down the drain after couple months.. and guess what your friend has? dat IP address!!
![[IMG]](http://remycarreiro.com/wp-content/uploads/2013/03/slapface-5000.jpg)
"You pussy you scared, I can hear your heart beat" Yeah 50 cent rocks! But really what can he really do with it? Nothing. Most average Joe cant do shit except for pinging your address with 64 bits haha lol'd.

![[IMG]](http://i.imgur.com/did9bXG.png)
But wait apparently your friend has taken a networking course called CCNA and probably knows a shit or two.. what's the most he can do? He can go buy a "Booter" and lit your ass up, not literally. He can probably take your cute internet connection down and null a port. So you cant visit facebook no more.
![[IMG]](http://cdn.meme.am/instances/60998065.jpg)
What else can he do?
- He can DOX you, using your IP address to filter information.
- He can search old hacked databases for your IP address and hack for email and shit if that site had not hashed data.
- He can post on online forums to DDOS that IP.
- He can do some port scanning shit.
How do I prevent all this?
- Don't signup on BS sites.
- Don't click shit links.
- Don't talk to strangers.
- Don't install bullshit.
- Don't ever use common sense. jk. But seriously avoid using common sense at all costs. It's expensive.
Blocking websites
So you clicked this somewhat bait title 'Blocking websites for noobs'
because you want to block certain websites... isn't? and perhaps
wondering if you already know what this dude chillin is about to teach
you. Wonder didn't Firefox or Chrome have that function? Yes it
certainly does.
But wait since it's a bait thread I'll teach you something else.
Obama care for good measure incase title hurt your butt.
Business time
Ever heard of Hosts file? no? then you're at a right place god dammit! Hosts file is like a pipeline where you add a filter in the middle to making sure what's allowed to flow and what is not. You can also Redirect user to different websites.
So if you open hosts file this is the format you put data in:
127.0.0.1 localhosts
'localhosts' is the URL a user would open. '127.0.0.1' is the URL 'localhosts' URL would be redirected to.
So for example if I have, 'www.google.com www.youtube.com' user would be redirected to www.google.com whenever he tried to open www.youtube.com. Isn't that interesting? You've just learned a new way to fuck your friend up!
You ask how do I block a website. Well just redirect website you want to block to 127.0.0.1 or any html that that you may have on your PC.
Not interesting enough?
Wait I heard Microsoft's new, windows 10 secretly sends data back and forth to some sites? We needa block that shit. RESPECT MY PRIVACY MOTHERFU*CKER.
What about blocking all the damn sites Microsoft windows 10 contacts? You could do that? you already know how to block shit using Hosts file, didn't you? all your have to do is find websites windows accesses.
If you like it. You must share it!
But wait since it's a bait thread I'll teach you something else.

Obama care for good measure incase title hurt your butt.
Business time
Ever heard of Hosts file? no? then you're at a right place god dammit! Hosts file is like a pipeline where you add a filter in the middle to making sure what's allowed to flow and what is not. You can also Redirect user to different websites.
So if you open hosts file this is the format you put data in:
127.0.0.1 localhosts
'localhosts' is the URL a user would open. '127.0.0.1' is the URL 'localhosts' URL would be redirected to.
So for example if I have, 'www.google.com www.youtube.com' user would be redirected to www.google.com whenever he tried to open www.youtube.com. Isn't that interesting? You've just learned a new way to fuck your friend up!

You ask how do I block a website. Well just redirect website you want to block to 127.0.0.1 or any html that that you may have on your PC.
Not interesting enough?
Wait I heard Microsoft's new, windows 10 secretly sends data back and forth to some sites? We needa block that shit. RESPECT MY PRIVACY MOTHERFU*CKER.
What about blocking all the damn sites Microsoft windows 10 contacts? You could do that? you already know how to block shit using Hosts file, didn't you? all your have to do is find websites windows accesses.
If you like it. You must share it!
Start your own online store with opencart
So you want to start online store, sell a few items and make profit?
![[IMG]](http://vignette1.wikia.nocookie.net/vsbattles/images/3/31/Meme-face-thinking.jpg/revision/latest?cb=20160207175639)
Opencart to rescue
If you haven't heard of opencart then you should learn a bit about it. It's an online eCommerce store to sell your products, accepts plenty of different payment options is pretty damn easy to setup and really make everything easy as hell through GUI.
Basically installation takes no more than 5 minutes. Create SQL database, download and extract opencart, put Upload folder files onto your host directory. Open your website root in browser and follow the instructions to setup admin login.
Sorry. PHP had to spoil the party!
![[IMG]](http://png-2.findicons.com/files/icons/2420/coded/256/page_php.png)
The only thing that may cause trouble while installing is not having modules enabled or having wrong PHP version, other that it's all easy.
Linux! Cant use Terminal, learn it? It seems useful.
![[IMG]](http://img.memecdn.com/update_o_986903.jpg)
If you're on Linux server just login and install modules typing sudo apt-get install php5-mcrypt for example. Or sudo apt-get install php5-curl. When going through wizard it should tell you what extensions to enable. Once installed you can enabled it by typing phpenmod Module_name.
You can also check manually what's installed that related to PHP. For instance use dpkg command with option --list and pipe the output to grep search command and search php. Like this. dpkg --list | grep php.
It's also necessary that you give certain file write permission. If you don't know how to do that, learn about linux permissions
![[IMG]](http://cdn.meme.am/instances/500x/64688451.jpg)
Naoooo it's actually that easy!
Once installed you can login to admin by going to www.your_site.com/admin and start adding or deleting products, set price, quantity, payment options, create categories.
![[IMG]](http://i.imgur.com/FfETpqU.png)
![[IMG]](http://i.imgur.com/UxBZgKx.png)
If you're setting up paypal as payment you can go to paypal developer account and get your data off there.
That's all there's to it guys. Using opencart is pretty easy as an end user.
![[IMG]](http://vignette1.wikia.nocookie.net/vsbattles/images/3/31/Meme-face-thinking.jpg/revision/latest?cb=20160207175639)
Opencart to rescue
If you haven't heard of opencart then you should learn a bit about it. It's an online eCommerce store to sell your products, accepts plenty of different payment options is pretty damn easy to setup and really make everything easy as hell through GUI.
Basically installation takes no more than 5 minutes. Create SQL database, download and extract opencart, put Upload folder files onto your host directory. Open your website root in browser and follow the instructions to setup admin login.
Sorry. PHP had to spoil the party!
The only thing that may cause trouble while installing is not having modules enabled or having wrong PHP version, other that it's all easy.
Linux! Cant use Terminal, learn it? It seems useful.
![[IMG]](http://img.memecdn.com/update_o_986903.jpg)
If you're on Linux server just login and install modules typing sudo apt-get install php5-mcrypt for example. Or sudo apt-get install php5-curl. When going through wizard it should tell you what extensions to enable. Once installed you can enabled it by typing phpenmod Module_name.
You can also check manually what's installed that related to PHP. For instance use dpkg command with option --list and pipe the output to grep search command and search php. Like this. dpkg --list | grep php.
It's also necessary that you give certain file write permission. If you don't know how to do that, learn about linux permissions
![[IMG]](http://cdn.meme.am/instances/500x/64688451.jpg)
Naoooo it's actually that easy!
Once installed you can login to admin by going to www.your_site.com/admin and start adding or deleting products, set price, quantity, payment options, create categories.
![[IMG]](http://i.imgur.com/FfETpqU.png)
![[IMG]](http://i.imgur.com/UxBZgKx.png)
If you're setting up paypal as payment you can go to paypal developer account and get your data off there.
That's all there's to it guys. Using opencart is pretty easy as an end user.
Tuesday, 8 March 2016
Port scanner, TCP/IP, Firewall & the Bouncer
Thought writing little something about what port scanners, TCP/IP and Firewall in general.
Read this. Don't skip!
When we talk about port it's necessary we also know what packet is. A pack it a little portion of a file that's transferred from one computer to another, and when this pack is transferred it's given destination and source IP address along with a port number. When a computer on receiving end receives this packet their firewall checks for rules set for that port or the IP. Firewall basically is like an entry point on your computer, everything that goes in or out goes through it.
See every app runs on different port. Must've heard of HTTP and FTP? no? Joined internet today or what?
FTP (File Transfer Protocol) - Port 21
SMTP (Simple Mail Transfer Protocol) - Port 25
Login (Login Host Protocol) - Port 49
HTTP (Hypertext Transfer Protocol) - Port 80 But I still don't understand??!

Right that's expected. Lets get a little more practical now. Your friend's computer wont open any webpage. He brings the computer to you and asks if you can fix. You check if it has internet. You do some other check but still cant figure out the problem.
--
What about checking whether firewall has port 80 opened? as you see, port 80 is used to make HTTP connections. It's possible that firewall is blocking it. Did you guys notice how workplace restricts your access to pornographic websites? Yes, firewalls list of rules are blocking those IP addresses.
So what's firewall again?

It's just a dude with list check-list in hand making sure who can come in, and how can go out. Understood? right! get a snicker!
TCP/IP(that's on scary acronym.. gonna drive me sane!) Don't worry.
Transmission control Protocol(TCP) is a language/protocol that ensures your packets are sent from one computer to another securely. You know when data is broken into packets it's a mess! thanks to TCP it's pasted back together into same order it when it goes to receiving end.
Okay..

This almighty TCP seem to know it all.. how does it know where to send data to? Well its friend Internet Protocol does! It contains the destination and source address and knows where the packet goes.
Alright? what's my IP address then? Click here to find out your IP address http://ipchicken.com/
Hmm.. What about TCP, can I see it too? Nop. But you can make sure it's running. If you send a packet using ping command followed by loopback address(this is virtual address for testing) it should return responses. Meaning TCP/IP is working properly. But you really shouldn't worry much about it because computers already comes with this stack installed.
What's port scanner?
As you seen above, different programs run on different protocol. If someone creates a program that checks for open ports on your computer and finds a vulnerability for that port then you're screwed isn't it. That's why people tell to keep un-used ports closed all the time. Check this PDF to find out common vulnerabilities on ports. http://www.tenable.com/sites/drupal...s/Vulnerability Reporting by Common Ports.pdf
Didn't understand anything? Well atleast you put some effort I guess? It's time you learn "basics of how Internet works".
Goodluck! any questions feel free to ask!
Monday, 7 March 2016
Codeigniter - How to fetch data from database and display
Show Data form Database to user
http://www.webdevtown.com/2016/02/mvc-model-view-controller-seriously.html
http://www.webdevtown.com/2016/02/codeigniter-beginners-series-lesson-2.html
Once you've gone through these two tutorials it's time to learn to retrieve information from database and show it on page. We'll just get all the records off database and show it.
Connect
First make sure to connect to database in '/var/www/application/config/database.php'
Set route
Once you've connected lets set default route to 'show_data'. Write $route['default_controller'] = 'show_data'. So whenever use loads your website default controller will run.
Create controller
Create a file named /var/www/application/application/Show_data.php make sure it starts with capital letter. Lets create a controller class. This class will run when user opens your site main page, if no method name is given in URL index method will be called.
PHP:
class Show_stats extends CI_Controller{
// This is default method that will run if no method name is given in url.
public function index(){
}
}
// This is default method that will run if no method name is given in url.
public function index(){
}
}
Model
Lets create model which will retrieve data from database. Create file /var/www/application/models/Stats_model.php and create a new model class and load database using constructor so it's loaded as soon as class is instantiated.
PHP:
class Stats_model extends CI_Model{
// We're loading database connection here.
function __construct(){
$this->load->database();
}
}
// We're loading database connection here.
function __construct(){
$this->load->database();
}
}
View
Create new file /var/www/application/views/show_data.php. This will is where we will pass data from that we get from model class.
Retrieve data in model.
We created model class earlier but didn't retrieve any data. Lets do it now. Create new function and retrieve all data from database.
PHP:
class Stats_model extends CI_Model{
function __construct(){
$this->load->database();
}
public function get_stats(){
// $this->db is an Object that has get method which accepts table name.
$query = $this->db->get('site_stats');
// We're returning all the data using $query->result_array();
return $query->result_array();
}
}
function __construct(){
$this->load->database();
}
public function get_stats(){
// $this->db is an Object that has get method which accepts table name.
$query = $this->db->get('site_stats');
// We're returning all the data using $query->result_array();
return $query->result_array();
}
}
Loading model into Controller
We created controller earlier but it doesn't do anything. We need to load model, invoke it's method to get the data and the pass it to views to show it to user.
PHP:
class Show_stats extends CI_Controller{
function __construct(){
// Running class CI_Controllers constructor.
parent::__construct();
// We load the model class.
$this->load->model('stats_model');
}
public function index(){
// We invoke get_stats method of stats_model class which retrieves data from database, and put them into an associative array $data[].
$data['stats'] = $this->stats_model->get_stats();
// We load view and pass it the $data array where we just put the retrieved values.
$this->load->view('stats', $data);
}
}
function __construct(){
// Running class CI_Controllers constructor.
parent::__construct();
// We load the model class.
$this->load->model('stats_model');
}
public function index(){
// We invoke get_stats method of stats_model class which retrieves data from database, and put them into an associative array $data[].
$data['stats'] = $this->stats_model->get_stats();
// We load view and pass it the $data array where we just put the retrieved values.
$this->load->view('stats', $data);
}
}
Show data in views
Go back to views and run simple foreach statement to show the data to user.
PHP:
<?PHP foreach($stats as $all_stats): ?>
<b>
<?PHP echo $all_stats['title']; ?>
</b>
<?PHP endforeach; ?>
<b>
<?PHP echo $all_stats['title']; ?>
</b>
<?PHP endforeach; ?>
Subscribe to:
Comments (Atom)