Top Interview Questions and Answers

Top Interview Questions and Answers
Interview Sortout

Browsing "Older Posts"

DBMS Interview Questions ans Answers - Basic Concepts

By Dhananjay yadav → January 25, 2018
What is DBMS?
A database management system (DBMS) is system software. The DBMS is used for creating databases and manipulating data and records in an organized way.

What is RDBMS?
RDBMS stands for Relational Database Management System. it is based on relational blocks.RDBMS replaces the traditional file system to store the data. All modern systems follow the concept of RDBMS. for example MS SQL Server, Oracle, MySQL etc.

SEO basic interview questions and answers

By Dhananjay yadav → January 24, 2018
What is SEO?
SEO or Search Engine Optimization is process to rank your website or blog well. A good rank means your website is indexed by search engines and will be found first if somebody searches the related keyword.The goal of SEO is to make your site reachable on www easily.

What are techniques used for SEO?
There are two broad categories of SEO techniques:
1- In page
2- Off Page
In page SEO means content and page element to be optimized for good rank and reachability. Off-page SEO is to promote your sites on different platforms and submit artificially in directories.

15 Advance Code Igniter Interview Questions and Answer

By Dhananjay yadav → January 23, 2018

How routing is beneficial in Code Igniter?
Routing provides a way to alter your URL and redefine it according to you. It helps in security and SEO. We can create URL having keywords and phrases influential for SEO ranking.

What is a helper?
Helpers are the file having functions for specific purposes. We can directly call them in our script.There is numerous type of helper:
  • Array Helper: It has functions that we use to manipulate arrays.
  • File Helper: Use of this helper is to play with files as upload an image.
  • HTML Helper : Html helper is used to compose HTML dom using php code.
  • URL Helper: We use it to create and construct or redirect URLs.

What does autoload.php do?
It loads when the application start loading contains and default parts of application call. It has information to load the segments that we need to load automatically. For example, we may need to load some models automatically.

How can we connect code igniter to our database?
There is a database.php file in the config directory. We can put here our database information like database name, hostname, username and password and It will be connected.

Can we call multiple model function in a single controller function?
Yes, of course. We can call any number of model and their functions in a single controller class?

Can we write database queries in a controller?
Yes, we can write database queries directly in controllers but this is not a good practice. We should write database queries always in the model.

How can we pass data to view?
We create an array having a particular key and pass this array to load view call. We will have this data on the view page as having the name of the key given to data array.

<?php
$data['employee']=array("name"=>"Dhananjay");
$this->load->view("employee_info",$data);
?>
Now on the employee_info.php page, we will have a $employee variable and that will store the data passed in the array $data in the controller.

How can we pass a parameter to controller function?
A parameter can be passed to URL segment after backslash next to function route. Suppose "admin" is a controller , "all_user" is a function and "active" is a parameter. Now we have to pass this to function that it can list the active user so we can call as given below:

<?php echo site_url("admin/all_user/active")?>

What is a library in Code Igniter?
Code Igniter library is a utility to extend the functionality and to use some predefined functions and classes. We have different libraries for different purposes as upload, database etc.

How can we execute a raw query in Code Igniter?
Using query builder library of code igniter we can execute raw query. For example,

db->query($sql);
$result=$query->result_array();
?>

What is URL helper?
We use URL helper to do manipulation with URL. We can easily create custom URL, we can extract parameters from URL, we can easily create custom anchors, form action, and page redirection.

How the database library provide strength to Code Igniter framework?
Database library has query builder functions. It works with single data and also in batch data. It accepts the array and single values as parameters. Functions are very similar to MySQL query phrases and keywords. We can use almost the query using query builder. It fetches the data in all possible formats. We can select, update, join, delete the records in very simple and robust way.

How we will submit data using a form on code igniter view?
We can give the controller function route as the form action. When we will submit this for, the controller function will be called and data will be collected using $_GET or $_POST arrays, as the method defined in the form.

How we create a session variable and how will we get that value stored in a session variable?
Code igniter has session library.It uses four types of the driver to store session data:
1-files
2-database
3-redis
4-Memcached
The file is the default storage.
After loading session library we can use session class and its method to set or get the session value.

<?php 
$this->load->library('session');
//set session data
$this->session->set_userdata('user_session_name', 'session_value');

//check session
$this->session->has_userdata('user_session_name', 'session_value');

//get session data
$this->session->get_userdata('user_session_name', 'session_value');

//destroy session data
$this->session->unset_userdata('user_session_name');
?>

How can we upload any file in Code Igniter application?
Code igniter has upload library. We will use this library and set preferences in $config variable.
After initializing library we use call do_upload() function and it will complete the task.

Regional Rural Bank Probationary Officer Interview questions and answers

By Dhananjay yadav → January 22, 2018
If you have qualified the Bank PO mains exam then you must be preparing yourself for the Interview.Now you are huddled about the interview regarding the questions to be asked by the interviewer in the interview session.The interview is all about and revolves around few simple questions and you have to answer what is being asked. No need to be descriptive.

Have a look at a real Interview :
Candidate Name: Paritosh Pandey
Facebook Profile: https://www.facebook.com/paritosh.pandey.505
Post for: Regional Rural Bank Probationary Officer
Date : 28:12:2017
Time : 3:12 PM
Place: Lucknow
Duration: About 15 minutes.


Question 1: Where are you from?
Answer by Paritosh: Sir, I belong to Azamgarh, UP.

Questions 2: What your father do?
Answer:  He is a Farmer .

Questions 3: How much Land your have?
Answer: He has --- acre of land.

Question 4: How many members are there in your family?
Answer: There are five members including me, my mother, brother, my sister and my father.

Questions 5: What your brother do?
Answer: He is a banker.

Questions about your qualification and interest
Questions 6: You have an Engineering degree, then why you are going to opt PO as career?
Answer: Sir, I have lack of interest in technology. I found better to have a nontechnical and a  public sector job.

Questions 7: What percentage did you score in your B.Tech?
Answers: It was 65.

Questions Based on Graduate Degree(1 questions)
Question 8: What is the difference between HTTP and HTTPS? (related to subject of graduating stream).

Questions based on some Banking Terms(2 Questions):
Question 9: What is refinance?
Answers: Refinance explained by Paritosh.

Question 10: What is disinvestment?
Answers: Disinvestment
explained by Paritosh.














HTML Interview Questions and Answers for Freshers

By Dhananjay yadav → January 20, 2018
HTML stands for Hyper Text Markup Language. We can not say that HTML is a programming language but a markup language. HTML uses markup tags and they are designed to perform some particular task. For Example, Paragraph tag p is used to include any paragraph in a web page, Anchor tag a is used to add a hyperlink in a page.
HTML is not only limited to design but also it has advanced and can be used to develop device compatible applications fro smart Television, Digital Advertisement Display etc.Whatever can be the server side language say JSP, ASP or PHP, Python or Ruby HTML will be the display part. When we are talking about a web page we are talking about an HTML page. Basically, it is part of Web Design and case insensitive. We can have following questions that can be asked in interviews:

What is HTML?
HTML is a markup language and used to design a web page using marking tags.

How can we create an HTML page?
We can create a plain text file and .htm or .html as an extension, it will be converted to the HTML page.

What is the basic structure of HTML page?
HTML page is devided in to three segments
(1) Document Type markup  that is  html
(2) Head and Title portion that is head and title
(3) Main Content or body portion

 <html>  

      <head>
           <title></title>
      </head>
      <body>
      </body>
 </html> 

What types of input tag are used nowadays?
There are many input tags introduced since HTML5. Some of the most used and popular input types are as below:
(1)text: this is used for alphabetical characters to input in the form.
(2)tel: this is used to input the telephone numbers
(3)date: date is used to input date.
(4)email: email is used to input date
(5)number: a number is used to input a number, negative, positive or zero
(6)textarea: Long text can be input using text area. For example, we can use to input the message in a contact form.
(7)Select type(combo): when we have to select from some options it may be multiple type selection.

    How many methods are there for a form?
    There are two methods for a form: get and post.

    What is  br tag? 
    It is called Break Line tag. When we have to break line in the paragraph we use Break Line tag.

    What is meta tag?
    Meta tag is a part of head section of a HTML page. It includes page information, content type information and device compatibility information. Meta tag helps page to be indexed in search engine directories.

    How we can include a style sheet in an HTML page?
    We can include a seperate style sheet using link tag inside head section.
     <link rel="stylesheet" type="text/css" href="style.css" />  

    What is arrtibutes of Tag?
    Every tag has some advanced and customize features that developer can enhace. These features are known as arrtibutes. For example "bgcolor" is backgroud color , "font-style","width","height","align" etc. How the content will display it depends on the value given to different properties of tags.

    What is table tag?
    table tag is used to create a tabular structure to represent some statistical data in a web page. Table has number of rows and number of columns in each rows.

    What are the arrtibutes of table tag?
    Arrtibutes of table tag are as below:
    1- Border
    2- Width
    3- Height
    4- Align
    5- Bgcolor etc.

    What is the use of anchor tag?
    Anchoe tag is used to create a hyperlink is a webpage. We can connect to pages on the site or any third pary link to our website. For exampe:
     <a href="www.facebook.com">Facebook</a>  

    List some attributes of anchor tag?
    Attributes of anchor tag are as below:
    (1)Href : What will be hyper link?
    (2)target : where to open the link?
    (3)title : what will be the title of tag, it will apear when mouse goes over link.

    What is a div tag?
    Div tag create a rectangular area in a web page. Further we can manipulate it using attributes and style. div tag is used to create layout of webpage.

    What is form?
    FORM tag is used to create a user form in web page to store user inputs. Input tags are used to collect the input values from user and form action hadle the request.

    How to write a form tag in a web page?
    We can include a form tag as given below:
     <form method="post" action="form-action.php">  
     <!---input elements--->
     </form>
    

    What is marquee tag?
    marquee tag is used to insert a moving element in the HTML page. For example, Notices are moving from left to right or top -bottom direction in an informational website.

    Create a table having table head and foot?
    We can create a table as given below:

     <table>  
    
          <thead>
               <tr>
                    <th></th>
                    <th></th>
               </tr>
          </thead>
          <tbody>
               <tr>
                    <td></td>
                    <td></td>
               </tr>
          </tbody>
          <tfoot>
               <tr>
                    <td></td>
                    <td></td>
               </tr>
          </tfoot>
     </table>
    


    How Many types are lists?
    There are three types of lists in HTML basically, as given below:
    1- Unordered List  implemet by ul tag
    2- Ordered list implement by ol tag
    3- Data list implement by dl tag

    What are the headings tag? What is the usage of Headings in HTML page?
    HTML provides heading tags to implement document heading in the page. There are 6 headings H1, H2......H6.H1 has the biggest font size by default so we can use it as the main heading and other can be used as subheadings.

    How can we include Javascript in HTML page?
    We can include javascript code inside html page using  script tag. We can directly write code of javascript in pgae or we can use a seperate javascript page.

    What is a responsive web page?
    A responsive webpage is dynamic view page that is compatible to different types of display and orientation. To make a page responsive we use media query and view port acces to control orientaion and layout.

    PHP-MySQL Interview Questions and Answers : Most Common Questions

    By Dhananjay yadav → January 19, 2018


    There are some basic PHP Interview questions, asked in every interview often. They must be known to every interview aspirants. Chances of asking these questions by Interviewer is very high because they just test your basic concepts of PHP.They highlight your understanding and command of the language. They are helpful to nail the first impression on interviewer when you are in the interview. An Interviewer expects that you should know the answers to these questions. After these questions, you will be asked to answer some hard-core questions and concepts. What we have given here is experienced. these questions give you the pattern of often asked question on Interview along with their answers. We try to give genuine answers, by verifying them from www.php.net, www.w3schools.com, and other popular tutorials site. After knowing the pattern It will be easy for you to explore more questions from various sources.


    What is PHP ?
    PHP is a server-side scripting language. It is lightweight as well as enriched with OOPs features. PHP is freely available and has lots of frameworks, CMS to built robust and secure applications.

    Explain these functions :
    echo( ),print( ),print_r( ),die( ),exit( ),var_dump( )
    var_dump($var):- Displays information about a variable.
    echo() or echo: This is not actually a function.This doesn't return a value after it takes parameter.
    print() pritn : This is also not a function ,accepts always single parameter and returns 1.
    print_r():-This prints the content and indexes of arrays and objects.
    exit:-It terminates the current script with a message.
    die(): This is identical to exit;

    What are the differences amongst include(), require(),require_once(), require(),include()?
    include(): Includes an external script into current script. On failure it emits Warning and allows script to continue, it does not terminate the execution of the script.
    include_once(): On failure emits an compile E_COMPILE_ERROR  error. It terminates the script execution.

    What is the difference between in_array() and is_array()?
    Both of these function returns a boolean type.
    in_array() :
    If a value finds within an array it returns TRUE otherwise returns false.
    is_array() :
    It checks whether the type of variable is an array or not. It returns true if an array is passed into it. It can be applied to any type of array.

    What is the difference between count() and sizeof()?
    Literally we can say there is no difference between these two terms. Both of these have Identical behaviors.
    count():- It counts all elements of an array or object.
    sizeof():-Identical to count(), can say Alias.

    What is the difference between json_encode() and json_decode()?
    json_encode() converts a PHP array or an object into json string, and json_decode() convers an JSON string into PHP array or into PHP object.

    Where do we store Session and Cookie?
    The session is stored on server whereas cookies are stored on the client machine in browsers.

    How we use foreach loop in PHP?
    Foreach loop is used to iterate an array or an object in PHP . For example

    <?php 
    foreach ($array as $key =>; $value){
    echo "$value is at $key place";
    }
    ?>
    
    
    
    What are the differences amongst trim(),ltrim(),rtrim()?
    • trim():-It removes white spaces from both the sides of a string.
    • ltrim():-It removes white space from left side of a string.
    • rtrim():-It removes white space from right side of a string.
    What are the constants , how we define them in PHP?
    A constant is a name assigned to a value. It is like Identifiers but cannot change during script execution. We can define them usually in UPPER_CASE underscored string without $. For example: define("CURRENT_YEAR", "2017");

    What is $_GLOBAL?
    $_GLOBAL Is a superglobal array and holds all the variables that are global and can be accessible from anywhere in the script. $_POST,$_GET,$_REQUEST,$_FILE,$_SESSION,$_COOKIE all are superglobal arrays available in PHP. We can call them anywhere in the script.

    What is the difference between MySQL and mysqli?
    MySQLi is the extension of MySQL and It is an improved version of MySQL. MySQLi supports OOPS features and compatible to PDO.

    What unlink() function do in PHP?
    It is used to delete a file or directory from its location.

    What are the basic differences amongst Warning, Fatal Error, and Notice?
    Fatal error results in the termination of script, No further execution of the script is possible when it happens. Whereas Notice does not terminate the script, rather it notifies about some tolerable mistake and script after that line is able to execute. Warnings are the deprecated and bearable things in scripts. The doesn't affect the result usually.

    What is the difference between array_diff() and array_filter()?
    array_diff() returns the array of values of difference of two arrays and array_filter() returns the arrays of values and filter null values or specific values. The function array_filter() also used a callback function but it is optional.

    What is the difference between array_serach() and in_array()?
    The method array_search() returns the key if the value is found in the array and the function in_array() return TRUE if it will find the values in the array. In case of a failure, both functions return FALSE.

    What strlen() do?
    strlen() is a PHP library function and it returns the length of string passed to it.

    How substr() works?
    substr() is a PHP library function and it returns the part of string passed with parameters to it. It accepts starting point, length of returning string and input string as parameters.

    How str_replace() works?
    It is used to replace a sub-string with another substring in an input string.

    Top 10 Interview Questions and Answers for PHP freshers

    By Dhananjay yadav →
    What is difference between $_GET and $_POST?
    $_GET stores data sent by HTML form 'get' method or the value of variable encoded with URL whereas the $_POST collects the data submitted by "post" method of HTML form. $_GET has a character limit whereas no such limit defined by PHP for the POST.

    How many types of array are there in PHP?
    Basically, there are three types of arrays in PHP
    1- Indexed arrays
    2- Associative arrays
    3- Multidimensional Arrays

    How to convert a string into array and vice-versa?
    We can cover an array into a string and a string into an array using explode() and implode() methods.These methods use some delimiter to concat values of arrays and also at the time of splitting a string into an array.


    How you can find IP address of Local machine accessing PHP sites?
    PHP has a number of superglobals.$_SERVER has some autodetected values. We can use this variable to get the IP address as given below:

    1
    $_SERVER['REMOTE_ADDR'] ; ?>


    In how many ways we can fetch data from MySQL database?
    There are four standard ways to fetch data from MySQL database in PHP. They are listed below:
    1-mysql_fetch_array()
    2-mysql_fetch_assoc()
    3-mysql_fetch_row()
    4-mysql_fetch_object()

    Is PHP an Open Source?
    Yes, PHP is absolutely free, and it is an Open Source.It can be used under GPL.

    Does PHP supports OOPs Features?
    Yes, PHP is a full-featured server-side scripting language and enriched with Object Oriented Programming system approach. We can define a class, constructor. We can create Objects and can implement oops features like Abstraction, Polymorphism, Inheritance, and Encapsulation.

    What is the difference between array_merge and array_combine?
    We can differentiate between the two terms while understanding their definitions.
    array_merge(): Merge Elements of arrays in a single array while preserving their indexes. But array_combine() returns a new array where values in one array are keys in new arrays and values of another array values in new arrays.

    What is the Latest stable version of PHP and MySQL?
    You should check these things before your Interview because the version the things are updating frequently.
    For PHP: www.php.net
    For MySQL: www.mysql.com

    OOPS interview questions and answers

    By Dhananjay yadav →
    What is OOPS(Object Oriented Programming System)?
    OOPS, that is Object Oriented Programming System is a modularized system of programming. Chunks of programs are designed in such a manner that we can reuse them, modify them and also can rework on them.

    What is a class?
    A class is a collection or a group to represent similar type entities having identical properties and behavior.A class does not exist in physical but a concept to visualize real-world entities.

    What is an object?
    An object is a blueprint of a class. It is a prototype what class defines. When we have a working object we can say it is an instance.

    How can we differentiate between Procedural Programming System and OOPS?
    An object-oriented language is based on modules that are Object but procedural programming has no such concepts.
    OOPS is able to encapsulate data and member functions in a single block but procedural programming language represents a discrete structure.
    A procedural language is based on top-down approach whereas object-oriented language is based on the bottom-up approach of the algorithm.
    A procedural language is rigid in nature, but OOPS provide flexibility and reusability of code.

    What are the basic pillars of OOPS?
    Fundamental pillars of OOPS and are as follows:
    1-Abstraction
    Hiding the sensitive data or the way of implementation, but revealing the necessary data to the end user.It limits the scope of variables, methods.Abstraction is to implement the security features in OOPS and so in application.
    2-Encapsulation
    Encapsulation is the wrapping of data and data functions in a single block of codes. It contains the data definitions and behavior definition in a single block that is Class.
    3-Inheritance
    Inheritance provides flexibility features to OOPS. It allows a class to share its functions, variables to other classes and the classes that will be using the functions definitions and data variables of other class called child class, and this phenomenon is called Inheritance.
    4-Polymorphism
    Polymorphism is a way to reimplement the methods in child-class or in a subclass that is already implemented in the parent class.It gives flexibility to an object to represent it and to use its many forms as per the function definitions in classes.

    What is a constructor in OOPS?
    The constructor is a method which is called automatically when an Object of a class is instantiated.The constructor has the same name as that of the class and it does not return.

    What is the basic difference between overloading and overriding?
    Overloading
    When two methods are defined with the same name in a single class but they must have different signatures, then this phenomenon is known as Overloading.
    overriding
    When a method defined in the parent class is reimplemented by subclass or child class, then this phenomenon is known as overriding.

    Difference between class and an object?
    A class is a definition and object is a prototype of that definition.An object contains states and behaviors and a class is a template of an object. An object is an instance of a class and it is working model of a definition that we can call a class.

    What are the specifiers?
    Specifiers or modifiers define the scope of variables and methods in OOPS.They implement a secure structure and access level in the architecture of an application.There is some important access specifiers are as follows:
    Private:
    Restricts the access to the class itself. Even Child or subclass are also not allowed to use private functions and data.
    Protected:
    A protected function or variable or member is accessible within the class and within the child class or subclass only. It cannot be accessible from anywhere else.
    Public:
    It provides an open accessibility to members. Either within the class or within child class or from anywhere in the script, It will be accessible.

    What is a destructor?
    the destructor is a function which can be called automatically when an object is deleted.

    Code igniter Interview Questions and Answers

    By Dhananjay yadav →


    What is MVC?
    MVC is a three-tier architecture of application development approach.Almost the popular languages use this pattern. MVC provides Modular structure to an application. Three interconnected parts are Model, View, and Controller.
    M: Model, that means data handling and information interchange. Implement CRUD.
    V: view i.e. front end and representational parts, where user interacts with machine
    C: Controller, The business login, handle user request an passes to model and in return provide results to the user.

    What is difference b/w MVC and HMVC?
    HMVC is a hierarchical MVC, The whole application is modularized in interconnected modules and each module has its own MODEL, VIEW, CONTROLLER. In HMVC a module is a complete package of User Interface, business logic, and data handling. So MVC is discrete whereas HMVC contains MVC at each level.

    How we can load a model in CI controller?
    We can call load a model in the constructor as given in the following example:

    1
    2
    3
    4
    //load model $this->load->('users_model','users');
    //call model
    $this->users->add_new_user($data);
    ?>

    We can also assign an alias to ci_model. We can use 'users' to call a model rather than calling 'users_model'.

    What is autoload.php in the config?
    This is a file where preloaders are defined. Suppose we want to include database library, any model, URL library, sessions etc, then we can assign all these things here.

    What helpers do in CI?
    Helpers are the simple PHP functions returning some values and we can call them anywhere in our project once we initialized them.

    What are the libraries in CI, explain some popular libraries?
    The library is the packages which are designed to implement a particular set of functionalities. For example Database. Once we Initialized it, we do any operation on the database.

    What are Hooks?
    Hooks provide flexibility to CI core. We can modify the core functionality of CI without disturbing core files and use hooks.Learn more about Hooks in CodeIgniter

    How we define URL and redirect in CI?
    We use URL helper and then we can create redirect links :

    1

    these functions provide the way to create URL.

    How to write a SELECT query in CI model?
    We can write a select query in code igniter using the standard conventions of CI as given below:

    1
    2
    3
    4
    //table name 'users' $this->db->select('users');
    $query=$this->db->get();
    $result=$query->result();
    ?>

    How to call a CI model Controller?
    The following example illustrates, how to call a model in code igniter controller:

    1
    2
    3
    4
    //load model $this->load->('users_model','users');
    //call model
    $this->users->add_new_user($data);
    ?>

    What are the views?
    A view is the display part of the application. It renders the results on screen and provides UI.We can assemble views files in directories as well.

    How we define controller in CI?
    A controller is the backbone of MVC. It creates a connection between model and view.We can define a controller as illustrated:

    1
    'BASEPATH') OR exit('No direct script access allowed');

    How controllers and models are different?
    Controllers deals with business logic. When user Instruct the machine to do something, controller listens to that response while interaction another side with a model for data. Whereas a model is data handling layer. It saves data to the database and it requests data from the database that further goes to the controller to display on view.

    What is the convention to call controller function with a parameter in CI?
    We can call a controller function in uri using the a pattern given below. First part of URI is base URL. Base URL followed by controller route and followed by function name , parameters.
    base_url/controller_name/controller_function/param1/param2
    [Controller Class]/[controller methos]/[parameters]

    How to write JOIN Query in Code Igniter?
    Code Igniter has a very rich Database library. It provides a flexible way to call and create logics. Either we can use raw queries or we can use join() function.

    1
    2
    3
    4
    5
    6
    $this->db->select('t1.name,t2.email');
        $this->db->from('table1 as t1');
        $this->db->join('table2 as t2', 't1.id = t2.user_id', 'left');
        $query = $this->db->get();
        return $query->result();
    ?>

    How to apply where clause in Code Igniter?
    Using Code Igniter Database library function 'where()' we can apply where clause.

    1
    2
    3
    4
    5
    6
    7
    8
    $where=array( 'email'=>me@example.com,
    'status'=>'active'
    );
    $this->db->select('name,email,mobile');
    $this->db->get('users');
    $query=$this->db->where($where);
    $result=$query->result();
    ?>

    What is routing?
    Routing is a way to define URI and how to call controller methods with a particular URI.
    Routing provides flexibility to change the way we call controller functions. We can rename controller and functions. This enhances the security features as well as we can create SEO friendly URLs.

    What is the way to fetch query results in CI?
    Ther are many ways to fetch result in Code Igniter. Some of them are as follows:
    result();
    result_array();
    row();
    row_array();
    unbuffered_row();

    How we call controller method using AJAX?
    Simply we can call the URL using proper method and parameters, and then handle those request on a controller and if required we can render a view.

    How to define a session variable in CI?
    First of all, we need to load session library and then we can call some library functions to accomplish this task:

    1
    2
    3
    4
    //load library $this->load->library('session');
    //define a session variable named 'user_id'
    $this->session->set_userdata('user_id', $user_id);
    ?>