AppDev PDF
AppDev PDF
$this->uri->segment
Answer PHP version that uses void return type, class constant visibility modifiers, null
types.
7.1
PHP is one of the most widely used and recognizable web technology used on the Internet.
True
The function or ci code to show or call the client-side "non-existing page" error
show_404()
The page that displays a message that the requested page was not found.
Error 404
Answer What functionality was added to PHP 5.1 as interface for accessing databases?
PDO
Answer Year that PHP was officially called Personal Home Page Tools.
1995
Answer Version of PHP that uses namespace support late static binding.
5.3
4.1
Element can be placed onto a web page in a pre-checked fashion by setting the checked attribute.
Checkbox
CI method or code that display/echo error messages when form_validation->run() returns false.
Validation_errors()
row_array() fetch the data as a single row and result_array() fetch the data as a multi-
dimensional array.
True
CI file directory where the database configuration settings and database groups is found.
Application/config/database.php
Define styles for your documents, including the design, layout and variations in display for
different devices and screen sizes.
CSS
Query Builder or Active Record pattern in CI replaces the traditional query string in php coding.
True
These are functions which are passed to another function and takes this "other function" as a
parameter.
Callbacks
.htaccess file that will automatically route the index.php next to the Controller
True
CI uses Model-Viewable-Controller architecture
False
To load the view, the function is like this: $this->load->view('name');
True
is the process of redirecting or remapping a controller class or method.
routing
CI, basically contains 4 main folders Application, System, User, Help Guide
False
variables are just like session variables except it is only available on the next request.
Flashdata
URI is the historical name that serve as persistent, location-independent identifiers allowing the
simple mapping of namespaces into a single URN namespace
False
What do you call the 3rd, 4th segment of the URI?
Parameters
Controller is also knows as the data access layer.
False
HTML is a requirement in Code igniter
True
IDENTIFICATION: What do you call the 1st segment of the URI?
Controller
Meaning of URN
Uniform resource name
Data Access Layer or Persistence Layer of the MVC Layered Architecture.
Model
functions to help you build your form easier and faster.
Form helper
Meaning of URL.
False
are function that is passed to another function and takes this "other function" as a parameter
callbacks
will be loaded by the controller passing the returned data from the model.
Answer 1
It can be said as the entry point of application.
Controller
Answer 3
Organization that sponsors CI
Ellislab
Answer 4
You can display the error 404 page by using what function
show_404()
Answer 5
What function can be used to access session variables on webpages?
session_start()
Answer 6
Function that fetch the data as a multi-dimentional array
result_array()
Answer 7
variables are session variables that expires with a given time limit.
Tempdata
Answer 8
Method will execute codes once the class is created or instantiated.
__construct
Answer 9
Function that fetch the data as a single row array
row_array()
File that will automatically route the index.php next to the Controller Answer 10
Form helper class helps us by returning formatted HTML form elements.
True
Method that accepts 'secondary recipients' that receives the mail just to keep them informed
matches form validation rule checks 3 fields that should have an equal or same value.
False
It is any process or technology that allows users who forgot their passwords authenticate and reset
the passwords of their account
Forgot password
Method that accepts the recipient's email address
An input required to verify the user's record existence in order to reset his/her password.
Method that returns a string containing any server messages, email header and email message.
Method that returns a string containing any server messages, email header and email message.
Topics
Introduction .................................................................................................................................. 2
Session Variables........................................................................................................................... 2
Learning Objectives
2. Identify the syntax in creating, loading and removing session variable in CI.
3. Apply the commands needed in creating, loading and removing sessions in CI.
Introduction
Session Variables
We already know that sessions in native PHP are the “superglobal” variables that can be
accessed anywhere on the web application because it is stored on the browser session. They can be set
and accessed like any ordinary variables except that it uses the $_SESSION.
In order to use and access session variables on webpages, we must put the session_start()
function. The unsetting of the variable can be done by using unset() function on variables or
CodeIgniter improve the utilization of session variables on its Session Library. It contains
different session methods with different functionalities to help us speed up the task and simplify coding.
There were the improved session variables, flashdata and tempdata. The only new here is the flashdata
and tempdata. Flashdata are session variables that are only available until the next request. If the same
webpage is requested, the flashdata will not be present as it expires on the first request. The Tempdata
are just like ordinary session variables but expires in the defined seconds. Flashdata and Tempdata were
previously discussed and used on our last chapter to help us display success or failed status messages.
You can load it in inside the controller’s constructor or on its methods by:
$this->load->library(‘session’)
or if you will frequently use it, make it autoloaded by adding the ‘session’ library in the library
You can declare your own session variable on the $_SESSION superglobal but for the sake of this
tutorial on CodeIgniter, let CI do their thing because it’s much more simplified and structured. When the
session library is loaded, you don’t need to write session_start all over and over again, just declare the
Example:
Example:
Note: $this->session->set_userdata() is also used to set or change an existing session variable value.
To use or access session variables and its value, you may use the userdata() method.
Example when you have ‘item’ session variable name, you’ll use:
$this->session->userdata(‘item’)
or simply call:
$this->session->item
$_SESSION[‘item’]
When you no longer need the session variable you have set, you can remove it
by using $this->session->unset_userdata()
$this->session->unset_userdata(‘item’)
$this->session->unset_userdata($session_array)
Similarly, you can use native PHP’s unset() function on $_SESSION superglobals:
unset( $_SESSION[‘item’] )
User access and restriction is one of the must-need functionality of any website applications.
Log In modules are needed to limit users from accessing off-limits and restricted webpages or content.
Websites with database interactivity provide users to gain access to its backend or Administration Panel.
For the sake of security, we need to encrypt the user_pass column with md5. Use the md5()
function in your query when inserting passwords. MD5 is an algorithm that is used in security hashing
that transforms data into a 128 bit string. It is claimed that every encrypted string is as unique as
fingerprint.
MySQL query:
The Log In form that accepts username and password. The form uses Form Helper to return
HTML Form elements. When the form is submitted, the post variables will be sent to the verify method of
Output:
Add the verify method on the Login controller with Form Validation:
We have set a required rule on both fields and a callback_check_user on the password field. This
callback will check the user if it exists. If the fields passed the validation, the page will be redirected to
the Home controller where only authorized or logged-in users can access.
The login method of the Login Model will check the user if the username and password
parameters matched a record from the database. If it finds one, it will prepare our session variables for
The islogged session variable will determine whether the user record is authenticated and will
The login method will check the username and password parameters if it exists on the ‘users’
After the Login functionality that checks allowed users, let’s create the landing page after the
The Home controller and its method is exclusively for registered users. At the constructor
method, we need to include a condition that checks if the user has privileges on the page using the
islogged session variable. If not, they will be redirected back to the login page.
This will display the user’s account name and a link for logging out
Output:
Log Out
To logout a user, all we need to do is unset the session variable that keeps us in: the islogged
variable. To keep it neat, we have to unset all of our session variables and redirect back to Login
controller.
Introduction to PHP
Learning Objectives
HTML FORMS
HTML Forms
Course Module
Web Development 2
PHP and HTML FORMS
Filename: basic.css
Course Module
Web Development 3
PHP and HTML FORMS
Filename: 11html_forms.html
Course Module
Web Development 4
PHP and HTML FORMS
Course Module
Web Development 5
PHP and HTML FORMS
Filename: 12Select_tag.html
Filename: 12Using_Select.php
Course Module
Web Development 6
PHP and HTML FORMS
Course Module
Web Development 7
PHP and HTML FORMS
Filename: 13using_textarea.html
Filename: 13using_textarea.php
Course Module
Web Development 8
PHP and HTML FORMS
Course Module
Web Development 9
PHP and HTML FORMS
Filename:
14using_radiobuttons.html
Filename:
14using_radiobuttons.php
Course Module
Web Development 10
PHP and HTML FORMS
Course Module
Web Development 11
PHP and HTML FORMS
Filename:
15using_checkboxes.html
Filename:
15using_checkboxes.php
Course Module
Web Development 12
PHP and HTML FORMS
Course Module
Web Development 13
PHP and HTML FORMS
Filename:
16assigning_values.html
Filename:
16assigning_values.php
Course Module
Web Development 14
PHP and HTML FORMS
APPENDING TEXT
Course Module
Web Development 15
PHP and HTML FORMS
Filename:
17appending_text.html
Filename: 17appending_text.php
Course Module
Web Development 16
PHP and HTML FORMS
Course Module
Web Development 17
PHP and HTML FORMS
References
Murach, J. (2014) Murach’s PHP and MYSQL (2nd Edition)
WEBSITE
http://php.net/
http://www.w3schools.com/php/
https://www.tutorialspoint.com/php/
Course Module
Web Development 1
PHP Basics
PHP Basics
Learning Objectives
INTRODUCTION
PHP BASICS
PHP Syntax
php
// PHP code goes here
?>
Every time you want to use php scripts, the codes must be
enclose inside <?php ?> , all codes that are place inside the php block
are read by the php.
PHP Comments
Course Module
Web Development 2
PHP Basics
Sample Code:
Filename: 02basics_adding_comments.php
In PHP, all keywords (e.g. if, else, while, echo, etc.), classes,
functions, and user-defined functions are NOT case-sensitive. In the
example below, all three echo statements below are legal (and equal):
Course Module
Web Development 3
PHP Basics
Sample Code:
Filename: 03case_sensitivity.php
Note: all variable names are case-sensitive. In the example below, only
the first statement will display the value of the $color variable (this is because
$color, $COLOR, and $coLOR are treated as three different variables):
Course Module
Web Development 4
PHP Basics
Sample Code:
Filename: 04case_sensitivity.php
PHP Variables
Course Module
Web Development 5
PHP Basics
Sample Code:
Filename: 05_PHP_Variables.php
Course Module
Web Development 6
PHP Basics
In PHP there are two basic ways to get output: echo and print.
echo and print are more or less the same. They are both used to output
data to the screen. The differences are small: echo has no return value
while print has a return value of 1 so it can be used in expressions. echo
can take multiple parameters (although such usage is rare) while print
can take one argument. echo is marginally faster than print.
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Course Module
Web Development 7
PHP Basics
Filename:
06_Variables1.php
Course Module
Web Development 8
PHP Basics
Filename:
07_Variables2.php
Course Module
Web Development 9
PHP Basics
Filename:
08_Variables3.php
Course Module
Web Development 10
PHP Basics
Filename:
09_Variables3.php
Course Module
Web Development 11
PHP Basics
String Concatenation
Filename:
10_String_Concatenation.php
Course Module
Web Development 12
PHP Basics
References
Murach, J. (2014) Murach’s PHP and MYSQL (2nd Edition)
WEBSITE
http://php.net/
http://www.w3schools.com/php/
https://www.tutorialspoint.com/php/
Course Module
Web Application Development 2
1
Views
Views
Introduction
A view is simply a web page, or a page fragment, like a header, footer,
sidebar, etc. Views serves as User Interfaces where web users can interact,
request and receive data. Controllers can load views and pass data to them
Creating Views
Views are php files containing html elements. They are stored in
application/views folder. Lets have an example of a view. Create a file place
it at application/views/ and give it a name index.php. now type the following
codes.
Now we need to load the index.php (view) to our controller. To load the view
we need go to the controller, name the file as Home.php directory should be
like this: application/controllers/Home.php
Course Module
To load the view, the function is like this $this->load->view('name'); the
name is the name of the view file, in our example to load the view you type
$this->load->view(‘index’);
To test it out, go to http://localhost/index.php/Home. This should output:
Controller View
);
//outputs:
//User: Cruz, Juan
$this->load->view(‘some_page’,
$data);
Let’s pass some data to our index.php view Update the index method on the
Home controller: Don’t forget the second parameter $data.
Web Application Development 2
3
Views
In this way, our title will be dynamic by using the $title variable.
Output:
Notice that our Title Bar show our passed $data[“title”] from our Controller
to our view using $title.
Course Module
$data is an associative array containing the key products with array values:
Spaghetti, Baked Mac, Fettucine, Lasagna and the key title contains “Products”
string for our <title>
And displays it on our view at application/views/products.php
The $data array from the Products controller was extracted to our view. It will
simply display the $title inside the <title> tag and loop our $products array
values into our <ul> (unordered list).
If you want to pass more values on variables or array, just store it on
$data associative array on the controller’s method and don’t forget to $this-
>load->view(‘your_view’, $data) with $data as the second parameter.
Example:
$data[“num_of_products”] = count(array('Spaghetti', 'Baked Mac',
'Fettucine', 'Lasagna'));
$data[“date_today”] = date(‘F d, Y’);
Output:
Understanding URI
What is URI? URI stands for Uniform Resource Identifier. It is a string of
characters used to identify a resource. URL (Uniform Resource Locator) and
URN (Uniform Resource Name) are forms of URI.
Location (URL)
URI
Name (URN)
URL URN
https://facebook.com.com/dustoutlaw23 /profile/dustoutlaw23
https://www.youtube.com/channel/UCNHX /channel/UCNHXyYCEqfm
yYCEqfmO8jBTlbFvLHA O8jBTlbFvLHA
URL is the location that includes the components: the path/method and the
domain. It is basically called Web Address. URN is the historical name that
serve as persistent, location-independent identifiers allowing the simple
mapping of namespaces into a single URN namespace.
URI Segments
URI segments in CodeIgniter:
http://www.websitedomain.com/controller/method/param1/param2...
1 2 3 4
After the domain name, the controller comes the 1st segment of the URI. The
second follows the method. The 3rd, 4th and so on are the parameters. These
Course Module
parameters are mostly required by the method, it can be used as control,
settings or input.
Examples:
products/view/3 Viewing Product with the id 3
salary/calculate_daily_gross/8/100 Calculating daily gross salary with
8 hrs worked and with the pay rate
of 100 per hour
To get the uri segments on the address bar, we will use $this->uri-
>segment(n) where n is the requested segment position number.
Example:
http://suzuki.com.ph/motors/motorcycles/big-bikes/bandit-650/
Code Return String
$this->uri->segment(1) motors
$this->uri->segment(2) motorcycles
$this->uri->segment(3) big-bikes
$this->uri->segment(4) bandit-650
To see how it works, add the spaghetti method on our Products controller:
application/controlers/Products.php
It will output:
Removing Index.php
http://localhost/index.php/controller/method/param
This makes our URL longer that it consumes space. Why not remove it to
make it cleaner? We are not referring all of our pages in a single php file and
by that it looks more confusing.
The Answer? Create an .htaccess file that will automatically route the
index.php next to the Controller
Web Application Development 2
7
Views
You can now type in the URL without the index.php! (e.g.
http://localhost/controller/method/param)
Routing
For a quick review, here’s an example of CodeIgniter URL:
http://www.websitedomain.com/controller/method/param1/param2...
And also you can do this:
http://www.websitedomain.com/profile/dustin
Instead of:
http://www.websitedomain.com/profile/view/23
Course Module
$route[“bikes”] = ‘motorcycles’;
A URL that contains ‘bikes’ as controller will be remapped to ‘motorcycles’
controller class
$route[“profle/dustin”] = ‘profile/view/23’;
A URL containing the first segment ‘profile’ and second segment ‘dustin’ will be
rerouted to ‘profile’ controller, to the view method and to the profile id.
$route[“bikes/(:any)”] = ‘motorcycles/bike_lookup’;
A URL that contains any character or word on the second segment will be
redirected to ‘motorcycles’ controller class and bike lookup method as it will
search the motorcycle database for any given word or character.
$route[“bikes/(:num)”] = ‘motorcycles/view/$1’;
A URL that contains the ‘bikes’ controller associated with any number will be
readdressed to the ‘motorcycles’ controller and will trigger the ‘view’ method
and will accept the given number as a parameter value.
404 Page
Have you ever encountered “Error 404: Page not found”? This happens when
you try to reach a webpage but could not be found on the server. This can be
because you typed In the URL incorrectly, the URL was moved or it does not
exist. CodeIgniter allows you to show this client-side error and use it to catch
errors on your code intentionally or not.
When an Error 404 is met, application/views/errors/html/error_404.php file
is shown. Now you know where to customize this error In CodeIgniter.
You can display the error 404 page by using the function show_404() in the
controller method.
Example:
References
Web Development 1
PHP and HTML FORMS
Introduction to PHP
Learning Objectives
HTML FORMS
HTML Forms
Course Module
Web Development 2
PHP and HTML FORMS
Filename: basic.css
Course Module
Web Development 3
PHP and HTML FORMS
Filename: 11html_forms.html
Course Module
Web Development 4
PHP and HTML FORMS
Course Module
Web Development 5
PHP and HTML FORMS
Filename: 12Select_tag.html
Filename: 12Using_Select.php
Course Module
Web Development 6
PHP and HTML FORMS
Course Module
Web Development 7
PHP and HTML FORMS
Filename: 13using_textarea.html
Filename: 13using_textarea.php
Course Module
Web Development 8
PHP and HTML FORMS
Course Module
Web Development 9
PHP and HTML FORMS
Filename:
14using_radiobuttons.html
Filename:
14using_radiobuttons.php
Course Module
Web Development 10
PHP and HTML FORMS
Course Module
Web Development 11
PHP and HTML FORMS
Filename:
15using_checkboxes.html
Filename:
15using_checkboxes.php
Course Module
Web Development 12
PHP and HTML FORMS
Course Module
Web Development 13
PHP and HTML FORMS
Filename:
16assigning_values.html
Filename:
16assigning_values.php
Course Module
Web Development 14
PHP and HTML FORMS
APPENDING TEXT
Course Module
Web Development 15
PHP and HTML FORMS
Filename:
17appending_text.html
Filename: 17appending_text.php
Course Module
Web Development 16
PHP and HTML FORMS
Course Module
Web Development 17
PHP and HTML FORMS
References
Murach, J. (2014) Murach’s PHP and MYSQL (2nd Edition)
WEBSITE
http://php.net/
http://www.w3schools.com/php/
https://www.tutorialspoint.com/php/
Course Module
Web Application Development 2
1
Views
Views
Introduction
A view is simply a web page, or a page fragment, like a header, footer,
sidebar, etc. Views serves as User Interfaces where web users can interact,
request and receive data. Controllers can load views and pass data to them
Creating Views
Views are php files containing html elements. They are stored in
application/views folder. Lets have an example of a view. Create a file place
it at application/views/ and give it a name index.php. now type the following
codes.
Now we need to load the index.php (view) to our controller. To load the view
we need go to the controller, name the file as Home.php directory should be
like this: application/controllers/Home.php
Course Module
To load the view, the function is like this $this->load->view('name'); the
name is the name of the view file, in our example to load the view you type
$this->load->view(‘index’);
To test it out, go to http://localhost/index.php/Home. This should output:
Controller View
);
//outputs:
//User: Cruz, Juan
$this->load->view(‘some_page’,
$data);
Let’s pass some data to our index.php view Update the index method on the
Home controller: Don’t forget the second parameter $data.
Web Application Development 2
3
Views
In this way, our title will be dynamic by using the $title variable.
Output:
Notice that our Title Bar show our passed $data[“title”] from our Controller
to our view using $title.
Course Module
$data is an associative array containing the key products with array values:
Spaghetti, Baked Mac, Fettucine, Lasagna and the key title contains “Products”
string for our <title>
And displays it on our view at application/views/products.php
The $data array from the Products controller was extracted to our view. It will
simply display the $title inside the <title> tag and loop our $products array
values into our <ul> (unordered list).
If you want to pass more values on variables or array, just store it on
$data associative array on the controller’s method and don’t forget to $this-
>load->view(‘your_view’, $data) with $data as the second parameter.
Example:
$data[“num_of_products”] = count(array('Spaghetti', 'Baked Mac',
'Fettucine', 'Lasagna'));
$data[“date_today”] = date(‘F d, Y’);
Output:
Understanding URI
What is URI? URI stands for Uniform Resource Identifier. It is a string of
characters used to identify a resource. URL (Uniform Resource Locator) and
URN (Uniform Resource Name) are forms of URI.
Location (URL)
URI
Name (URN)
URL URN
https://facebook.com.com/dustoutlaw23 /profile/dustoutlaw23
https://www.youtube.com/channel/UCNHX /channel/UCNHXyYCEqfm
yYCEqfmO8jBTlbFvLHA O8jBTlbFvLHA
URL is the location that includes the components: the path/method and the
domain. It is basically called Web Address. URN is the historical name that
serve as persistent, location-independent identifiers allowing the simple
mapping of namespaces into a single URN namespace.
URI Segments
URI segments in CodeIgniter:
http://www.websitedomain.com/controller/method/param1/param2...
1 2 3 4
After the domain name, the controller comes the 1st segment of the URI. The
second follows the method. The 3rd, 4th and so on are the parameters. These
Course Module
parameters are mostly required by the method, it can be used as control,
settings or input.
Examples:
products/view/3 Viewing Product with the id 3
salary/calculate_daily_gross/8/100 Calculating daily gross salary with
8 hrs worked and with the pay rate
of 100 per hour
To get the uri segments on the address bar, we will use $this->uri-
>segment(n) where n is the requested segment position number.
Example:
http://suzuki.com.ph/motors/motorcycles/big-bikes/bandit-650/
Code Return String
$this->uri->segment(1) motors
$this->uri->segment(2) motorcycles
$this->uri->segment(3) big-bikes
$this->uri->segment(4) bandit-650
To see how it works, add the spaghetti method on our Products controller:
application/controlers/Products.php
It will output:
Removing Index.php
http://localhost/index.php/controller/method/param
This makes our URL longer that it consumes space. Why not remove it to
make it cleaner? We are not referring all of our pages in a single php file and
by that it looks more confusing.
The Answer? Create an .htaccess file that will automatically route the
index.php next to the Controller
Web Application Development 2
7
Views
You can now type in the URL without the index.php! (e.g.
http://localhost/controller/method/param)
Routing
For a quick review, here’s an example of CodeIgniter URL:
http://www.websitedomain.com/controller/method/param1/param2...
And also you can do this:
http://www.websitedomain.com/profile/dustin
Instead of:
http://www.websitedomain.com/profile/view/23
Course Module
$route[“bikes”] = ‘motorcycles’;
A URL that contains ‘bikes’ as controller will be remapped to ‘motorcycles’
controller class
$route[“profle/dustin”] = ‘profile/view/23’;
A URL containing the first segment ‘profile’ and second segment ‘dustin’ will be
rerouted to ‘profile’ controller, to the view method and to the profile id.
$route[“bikes/(:any)”] = ‘motorcycles/bike_lookup’;
A URL that contains any character or word on the second segment will be
redirected to ‘motorcycles’ controller class and bike lookup method as it will
search the motorcycle database for any given word or character.
$route[“bikes/(:num)”] = ‘motorcycles/view/$1’;
A URL that contains the ‘bikes’ controller associated with any number will be
readdressed to the ‘motorcycles’ controller and will trigger the ‘view’ method
and will accept the given number as a parameter value.
404 Page
Have you ever encountered “Error 404: Page not found”? This happens when
you try to reach a webpage but could not be found on the server. This can be
because you typed In the URL incorrectly, the URL was moved or it does not
exist. CodeIgniter allows you to show this client-side error and use it to catch
errors on your code intentionally or not.
When an Error 404 is met, application/views/errors/html/error_404.php file
is shown. Now you know where to customize this error In CodeIgniter.
You can display the error 404 page by using the function show_404() in the
controller method.
Example:
References
Web Development
Topics
Introduction .................................................................................................................................. 2
Session Variables........................................................................................................................... 2
Learning Objectives
2. Identify the syntax in creating, loading and removing session variable in CI.
3. Apply the commands needed in creating, loading and removing sessions in CI.
Introduction
Session Variables
We already know that sessions in native PHP are the “superglobal” variables that can be
accessed anywhere on the web application because it is stored on the browser session. They can be set
and accessed like any ordinary variables except that it uses the $_SESSION.
In order to use and access session variables on webpages, we must put the session_start()
function. The unsetting of the variable can be done by using unset() function on variables or
CodeIgniter improve the utilization of session variables on its Session Library. It contains
different session methods with different functionalities to help us speed up the task and simplify coding.
There were the improved session variables, flashdata and tempdata. The only new here is the flashdata
and tempdata. Flashdata are session variables that are only available until the next request. If the same
webpage is requested, the flashdata will not be present as it expires on the first request. The Tempdata
are just like ordinary session variables but expires in the defined seconds. Flashdata and Tempdata were
previously discussed and used on our last chapter to help us display success or failed status messages.
You can load it in inside the controller’s constructor or on its methods by:
$this->load->library(‘session’)
or if you will frequently use it, make it autoloaded by adding the ‘session’ library in the library
You can declare your own session variable on the $_SESSION superglobal but for the sake of this
tutorial on CodeIgniter, let CI do their thing because it’s much more simplified and structured. When the
session library is loaded, you don’t need to write session_start all over and over again, just declare the
Example:
Example:
Note: $this->session->set_userdata() is also used to set or change an existing session variable value.
To use or access session variables and its value, you may use the userdata() method.
Example when you have ‘item’ session variable name, you’ll use:
$this->session->userdata(‘item’)
or simply call:
$this->session->item
$_SESSION[‘item’]
When you no longer need the session variable you have set, you can remove it
by using $this->session->unset_userdata()
$this->session->unset_userdata(‘item’)
$this->session->unset_userdata($session_array)
Similarly, you can use native PHP’s unset() function on $_SESSION superglobals:
unset( $_SESSION[‘item’] )
User access and restriction is one of the must-need functionality of any website applications.
Log In modules are needed to limit users from accessing off-limits and restricted webpages or content.
Websites with database interactivity provide users to gain access to its backend or Administration Panel.
For the sake of security, we need to encrypt the user_pass column with md5. Use the md5()
function in your query when inserting passwords. MD5 is an algorithm that is used in security hashing
that transforms data into a 128 bit string. It is claimed that every encrypted string is as unique as
fingerprint.
MySQL query:
The Log In form that accepts username and password. The form uses Form Helper to return
HTML Form elements. When the form is submitted, the post variables will be sent to the verify method of
Output:
Add the verify method on the Login controller with Form Validation:
We have set a required rule on both fields and a callback_check_user on the password field. This
callback will check the user if it exists. If the fields passed the validation, the page will be redirected to
the Home controller where only authorized or logged-in users can access.
The login method of the Login Model will check the user if the username and password
parameters matched a record from the database. If it finds one, it will prepare our session variables for
The islogged session variable will determine whether the user record is authenticated and will
The login method will check the username and password parameters if it exists on the ‘users’
After the Login functionality that checks allowed users, let’s create the landing page after the
The Home controller and its method is exclusively for registered users. At the constructor
method, we need to include a condition that checks if the user has privileges on the page using the
islogged session variable. If not, they will be redirected back to the login page.
This will display the user’s account name and a link for logging out
Output:
Log Out
To logout a user, all we need to do is unset the session variable that keeps us in: the islogged
variable. To keep it neat, we have to unset all of our session variables and redirect back to Login
controller.
PHP Basics
Learning Objectives
INTRODUCTION
PHP BASICS
PHP Syntax
php
// PHP code goes here
?>
Every time you want to use php scripts, the codes must be
enclose inside <?php ?> , all codes that are place inside the php block
are read by the php.
PHP Comments
Course Module
Web Development 2
PHP Basics
Sample Code:
Filename: 02basics_adding_comments.php
In PHP, all keywords (e.g. if, else, while, echo, etc.), classes,
functions, and user-defined functions are NOT case-sensitive. In the
example below, all three echo statements below are legal (and equal):
Course Module
Web Development 3
PHP Basics
Sample Code:
Filename: 03case_sensitivity.php
Note: all variable names are case-sensitive. In the example below, only
the first statement will display the value of the $color variable (this is because
$color, $COLOR, and $coLOR are treated as three different variables):
Course Module
Web Development 4
PHP Basics
Sample Code:
Filename: 04case_sensitivity.php
PHP Variables
Course Module
Web Development 5
PHP Basics
Sample Code:
Filename: 05_PHP_Variables.php
Course Module
Web Development 6
PHP Basics
In PHP there are two basic ways to get output: echo and print.
echo and print are more or less the same. They are both used to output
data to the screen. The differences are small: echo has no return value
while print has a return value of 1 so it can be used in expressions. echo
can take multiple parameters (although such usage is rare) while print
can take one argument. echo is marginally faster than print.
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Course Module
Web Development 7
PHP Basics
Filename:
06_Variables1.php
Course Module
Web Development 8
PHP Basics
Filename:
07_Variables2.php
Course Module
Web Development 9
PHP Basics
Filename:
08_Variables3.php
Course Module
Web Development 10
PHP Basics
Filename:
09_Variables3.php
Course Module
Web Development 11
PHP Basics
String Concatenation
Filename:
10_String_Concatenation.php
Course Module
Web Development 12
PHP Basics
References
Murach, J. (2014) Murach’s PHP and MYSQL (2nd Edition)
WEBSITE
http://php.net/
http://www.w3schools.com/php/
https://www.tutorialspoint.com/php/
Course Module
Web Application Development 2
1
Introduction
Introduction
Introduction
Learning and Development in PHP is simple. CodeIgniter – “a powerful PHP
framework with a very small footprint, built for developers who need a
simple and elegant toolkit to create full-featured web applications.” It sounds
very complex but it’s pretty straightforward.
CodeIgniter is developed by Ellislab and used by millions worldwide.
Developers prefer to use CI for its rapid application development. It has rich
and reusable libraries and class for your website’s foundation.
Instead of creating your website from native PHP scratch, why not make it
more organized and powerful using CodeIgniter.
Skills needed
The following are the items you need to know before starting to play around
CI.
PHP – A good understanding of the PHP language is a must. As long as you
can perform simple instructions (e.g. variable declaration/assignments,
conditions, loops), you will nearly understand everything here since the
CodeIgniter is made up of PHP!
Course Module
HTML – Well, you do need those html elements to manipulate to. You’ll use
this for the layout design, inputs and presentation of data.
CSS – It’s good if you know Cascading Style Sheets (CSS), and even better if
you’re using external style sheets. There are more web design processors
available if you want to level-up your knowledge on styling however if you
don’t know how, still, you can learn CI.
MySQL – This means your SQL Basic queries are required. There will some
modules on this book where you need to manipulate I/O (inputs and
outputs) from your data storage or your database. Models communicate with
the database and uses your fundamental knowledge on SQL.
JavaScript – It makes the website interact with the HTML elements. If you do
not know JS, maybe learn it sometime, okay? You need these for future
developments.
CI Installation
Step 1. Visit its website on https://www.codeigniter.com/
Step 2. Find your way to the Download link and click Download.
The current version is 3.0.6
Step 3. Extract the downloaded .zip file and place it on your local server.
Make sure your Apache server is running and online then do:
Web Application Development 2
3
Introduction
Step 4. If you can see this Welcome Message. Your installation was a
success!
Course Module
Controller – This contains the Business logic (Business Logic Layer). The
controller controls the Model and View. A controller is a class that contains
methods that decides what to call, or perform and display.
When a user sends a request on a browser, the controller will determine the
process and perform tasks based on its method; it includes calling a method
returning a value from a model, displaying and passing values on a view or
showing a 404 error page.
Views – The Presentation layer. This contains designs, layouts or templates. It
is the collection of what will show up on your browser. The view is where the
user sees and interacts with.
Models – It is also referred as the Data Access Layer. The Model
communicates with your database. It comprises of methods that execute
queries using the CodeIgniter’s Active Record pattern.
CI Directory
Basically, CodeIgniter has 3 main folders: Application, System and User
Guide. You will work with your website in Application Folder. The System
folder, keep it a habit to avoid making changes to any of the files inside. It
contains the CodeIgniter’s core files which is necessary to make it run.
User_Guide contains the offline documentations you need in developing with
websites in CI.
Web Application Development 2
5
Introduction
Course Module
• Logs: This directory will include all application logs. TO know how to
write log for debug/error/info, please more about error handling
• Migrations: This directory will include migration helpers.
• Models: This directory will include all model classes used in our
application. This section can be said as the ‘data access layer’ of our
application.
• Third_party : This directory will include library files, but only those,
which are imported from third-party. So, difference between the
‘third_party’ and ‘libraries’ is that, one is for self-made libraries, for
app specific, other one is for importing party libraries.
• Views : This directory will include all view template files.
Introduction
Introduction
Learning and Development in PHP is simple. CodeIgniter – “a powerful PHP
framework with a very small footprint, built for developers who need a
simple and elegant toolkit to create full-featured web applications.” It sounds
very complex but it’s pretty straightforward.
CodeIgniter is developed by Ellislab and used by millions worldwide.
Developers prefer to use CI for its rapid application development. It has rich
and reusable libraries and class for your website’s foundation.
Instead of creating your website from native PHP scratch, why not make it
more organized and powerful using CodeIgniter.
Skills needed
The following are the items you need to know before starting to play around
CI.
PHP – A good understanding of the PHP language is a must. As long as you
can perform simple instructions (e.g. variable declaration/assignments,
conditions, loops), you will nearly understand everything here since the
CodeIgniter is made up of PHP!
Course Module
HTML – Well, you do need those html elements to manipulate to. You’ll use
this for the layout design, inputs and presentation of data.
CSS – It’s good if you know Cascading Style Sheets (CSS), and even better if
you’re using external style sheets. There are more web design processors
available if you want to level-up your knowledge on styling however if you
don’t know how, still, you can learn CI.
MySQL – This means your SQL Basic queries are required. There will some
modules on this book where you need to manipulate I/O (inputs and
outputs) from your data storage or your database. Models communicate with
the database and uses your fundamental knowledge on SQL.
JavaScript – It makes the website interact with the HTML elements. If you do
not know JS, maybe learn it sometime, okay? You need these for future
developments.
CI Installation
Step 1. Visit its website on https://www.codeigniter.com/
Step 2. Find your way to the Download link and click Download.
The current version is 3.0.6
Step 3. Extract the downloaded .zip file and place it on your local server.
Make sure your Apache server is running and online then do:
Web Application Development 2
3
Introduction
Step 4. If you can see this Welcome Message. Your installation was a
success!
Course Module
Controller – This contains the Business logic (Business Logic Layer). The
controller controls the Model and View. A controller is a class that contains
methods that decides what to call, or perform and display.
When a user sends a request on a browser, the controller will determine the
process and perform tasks based on its method; it includes calling a method
returning a value from a model, displaying and passing values on a view or
showing a 404 error page.
Views – The Presentation layer. This contains designs, layouts or templates. It
is the collection of what will show up on your browser. The view is where the
user sees and interacts with.
Models – It is also referred as the Data Access Layer. The Model
communicates with your database. It comprises of methods that execute
queries using the CodeIgniter’s Active Record pattern.
CI Directory
Basically, CodeIgniter has 3 main folders: Application, System and User
Guide. You will work with your website in Application Folder. The System
folder, keep it a habit to avoid making changes to any of the files inside. It
contains the CodeIgniter’s core files which is necessary to make it run.
User_Guide contains the offline documentations you need in developing with
websites in CI.
Web Application Development 2
5
Introduction
Course Module
• Logs: This directory will include all application logs. TO know how to
write log for debug/error/info, please more about error handling
• Migrations: This directory will include migration helpers.
• Models: This directory will include all model classes used in our
application. This section can be said as the ‘data access layer’ of our
application.
• Third_party : This directory will include library files, but only those,
which are imported from third-party. So, difference between the
‘third_party’ and ‘libraries’ is that, one is for self-made libraries, for
app specific, other one is for importing party libraries.
• Views : This directory will include all view template files.
Identification. Write your answer on the space provided. Year that PHP 3 was released.
Answer: 1998
Identification. Write your answer on the space provided. What functionality was added to PHP 5.1 as interface for
accessing databases?
Answer: PDO
Identification. Write your answer on the space provided. Version of PHP what uses namespace support late static
binding
Answer: 5.3
Identification. Write your answer on the space provided. PHP version that uses void return type, class constant
visibility modifiers, null types
Answer: 7.1
Identification. Write your answer on the space provided. PHP version that enabled the filter extension by default
Native JSON default
Answer: 5.2
Identification. Write your answer on the space provided. PHP version currently in use on most websites and
included several new features such as support for object-oriented programming
Answer: PHP 5
PHP is one of the most widely used and recognizable web technology use on the internet.
Select one:
True
False
PHP runs on various platforms operating system such as apache and IIS
Select one:
True
False
comment
Script use in every php code. (Note : No spaces needed)
<?php?>
PHP in now known as "PHP: Hypertexts Preprocessor"
false
Define styles for your documents, including the design, layout and variations in
display for different devices and screen sizes.
CSS
Identification. Write your answer on the space provided. PHP version that uses
void return type, class constant visibility modifiers, null types
php 7.1
Symbol used to combine 2 sting values to create one string.
.
Symbol use to append data or string
.=
PHP is proprietary software.
false
PHP 3 was released in 1998.
true
What does PHP stand for?
PHP: Hypertext Preprocessor
PHP variables need to be declared before adding a value to it?
false
PHP can be run on Microsoft Windows IIS(Internet Information Server):
false
Which one of these variables has an illegal name?
$my-Var
It is a function that removes an existing file from the server.
unlink
</body>
</html>
All are benefits of information protection except one.
Failure to protect sensitive information can result in __________ issued by regulatory agencies
or lawsuits from other companies or individuals.
Ans : fines
In addition to security, information assurance ensures the identified answers except one.
In IA, this automatically happened as well as availability and reliable and timely access to
information.
Ans : confidentiality
No organization can be considered "safe" for any time beyond the last verification of
adherence to its policy.
Ans : security
Ans : confidentiality
Ans : integrity
This is an assurance that the systems responsible for delivering, storing, and processing
information are accessible when needed, by those who need them.
Ans : availability
This is "the environment in which communication over computer networks occurs.“
Ans : cyberspace
The state of being protected against the criminal or unauthorized use of electronic data, or
the measures taken to achieve this.
cyber security
This refers to the body of technologies, processes, and practices designed to protect
networks, devices, programs, and data from attack, damage, or unauthorized access.
cyber security
intellectual property
Organizations transmit sensitive data across networks and to other devices in the course of
doing businesses, and this describes the discipline dedicated to protecting that information
and the systems used to process or store it.
cyber security
As the volume and sophistication of cyber attacks grow, companies and organizations need
to take steps to protect their sensitive business and personnel information.
'True'.
The organizations and the government have focused most of their cyber security resources
on perimeter security to protect all the encrypted system components.
'False'.
This issued guidelines in its risk assessment framework that recommend a shift
toward continuous monitoring and real-time assessment.
This advises that companies must be prepared to “respond to the inevitable cyber incident,
restore normal operations, and ensure that company assets and the company’s reputation are
protected.”
NCSA
_______________ should also consider any regulations that impact the way the company
collects, stores, and secures data, such as PCI-DSS, HIPAA, SOX, FISMA.
Following a cyber risk assessment, develop and implement a plan to mitigate cyber risk and
protect the “_____________” outlined in the assessment.
crown jewels
cyber criminals
This consists of the cyber-physical systems that modern societies rely on.
agricultural farm
Negotiations are much more accessible over networks, causing the adoption of security
measures during the development phase to be an imperative phase of the project.
False'
photo enhancement
This ensures that internal networks are secure by protecting the infrastructure and inhibiting
access to it.
network security
These are all common examples of network security implementation except one.
These are constantly creating and implementing new security tools to help enterprise users
better secure their data.
cloud providers
The data is more secure when stored on physical servers and systems the user owned and
controlled.
'False'.