Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 994357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:33:45+00:00 2026-05-16T06:33:45+00:00

How can i create a main page with codeigniter? That page should contain a

  • 0

How can i create a main page with codeigniter?

That page should contain a few links like login, register, etc.

I followed a tut to create a login screen. But it made codeigniter only for that purpose. This is the site i’m talking about:

http://tutsmore.com/programming/php/10-minutes-with-codeigniter-creating-login-form/

So basically what im trying to is, use codeigniter for more things than just a login form.

My try routes.php i set these settings:

$route['default_controller'] = "mainpage";
$route['login'] = "login";

My mainpage.php file:

class Mainpage extends Controller
{
    function Welcome()
    {
        parent::Controller();
    }

    function index()
    {

        $this->load->view('mainpage.html');
    }
}

Mainpage.html:

<HTML>

<HEAD>
<TITLE></TITLE>
<style>
      a.1{text-decoration:none}
      a.2{text-decoration:underline}
</style>

</HEAD>

<BODY>

     <a class="2" href="login.php">login</a>

</BODY>
</HTML>

Login.php looks exactly like the one in that website which i provided the link for in this post:

Class Login extends Controller
{
    function Login()
    {
        parent::Controller();
    }

    function Index()
    {
        $this->load->view('login_form');
    }

    function verify()
    {
        if($this->input->post('username'))
        { //checks whether the form has been submited
            $this->load->library('form_validation');//Loads the form_validation library class
            $rules = array(
                array('field'=>'username','label'=>'username','rules'=>'required'),
                array('field'=>'password','label'=>'password','rules'=>'required')
            );//validation rules

            $this->form_validation->set_rules($rules);//Setting the validation rules inside the validation function
            if($this->form_validation->run() == FALSE)
            { //Checks whether the form is properly sent
                $this->load->view('login_form'); //If validation fails load the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> form again
            }
            else
            {
                $result = $this->common->login($this->input->post('username'),$this->input->post('password')); //If validation success then call the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> function inside the common model and pass the arguments
                if($result)
                { //if <b style="color: black; background-color: rgb(153, 255, 153);">login</b> success
                    foreach($result as $row)
                    {
                        $this->session->set_userdata(array('logged_in'=>true,'id'=>$row->id,'username'=>$row->username)); //set the data into the session
                    }

                    $this->load->view('success'); //Load the success page
                }
            else
            { // If validation fails.
                    $data = array();
                    $data['error'] = 'Incorrect Username/Password'; //<b style="color: black; background-color: rgb(160, 255, 255);">create</b> the error string
                    $this->load->view('login_form', $data); //Load the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> page and pass the error message
                }
            }
        }
        else
        {
            $this->load->view('login_form');
        }
    }
}

What am i missing guys?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:33:46+00:00Added an answer on May 16, 2026 at 6:33 am

    You’re using CodeIgniter, right? Do you have some stipulation in your config that you must use .php as an extension on all URLs? If not, you should be sending your hrefs to “/login” not “/login.php”. Furthermore, if you haven’t removed the “index.php” from your URL in your htaccess file and CI config, you’ll probably need to include that in your links.

    Furthermore, if I were you, I’d not follow what Sarfraz does in his Mainpage.php file. You shouldn’t be using standard PHP includes in CodeIgniter. Anything that is done with an include can easily be done by loading a view. For example, if you want to load the view as a string, you can say:

    $loginViewString = $this->load->view('login.php', '', true);
    

    Where the second parameter is whatever information you want passed to your view in an associative array where the key is the name of the variable you’ll be passing and the value is the value. That is…

    $dataToPassToView = array('test'=>'value');
    $loginViewString = $this->load->view('login.php', $dataToPassToView, true);
    

    And then in your login.php view you can just reference the variable $test which will have a value of “value”.

    Also, you don’t really need to have that “login” route declared since you’re just redirecting it to the “login” controller. What you could do is have a “user” controller with a “login” method and declare your route like this:

    $routes['login'] = 'user/login';
    

    EDIT…

    OK, I think this has perhaps strayed one or two steps too far in the wrong direction. Let’s start over, shall we?

    First let’s start with a list of the files that are relevant to this discussion:

    1. application/controllers/main.php (this will be your “default” controller)
    2. application/controllers/user.php (this will be the controller that handles user-related requests)
    3. application/views/header.php (I usually like to keep my headers and footers as separate views, but this is not necessary…you could simply echo the content as a string into a “mainpage” view as you’re doing….though I should mention that in your example it appears you’re forgetting to echo it into the body)
    4. application/views/footer.php
    5. application/views/splashpage.php (this is the content of the page which will contain the link to your login page)
    6. application/views/login.php (this is the content of the login page)
    7. application/config/routes.php (this will be used to reroute /login to /user/login)

    So, now let’s look at the code in each file that will achieve what you’re trying to do. First the main.php controller (which, again, will be your default controller). This will be called when you go to your website’s root address… http://www.example.com

    application/controllers/main.php

    class Main extends Controller
    {
        function __construct() //this could also be called function Main(). the way I do it here is a PHP5 constructor
        {
            parent::Controller();
        }
    
        function index()
        {
            $this->load->view('header.php');
            $this->load->view('splashpage.php');
            $this->load->view('footer.php');
        }
    }
    

    Now let’s take a look at the header, footer, and splashpage views:

    application/views/header.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta name="description" content="This is the text people will read about my website when they see it listed in search engine results" /> 
    <title>Yustme's Site</title> 
    
    <!-- put your CSS includes here -->
    
    </head> 
    
    <body>
    

    application/views/splashpage.php – note: there’s no reason why you need a wrapper div here…it’s only put there as an example

    <div id="splashpagewrapper">
        <a href="/login">Click here to log in</a>
    </div>
    

    application/views/footer.php

    </body>
    <!-- put your javascript includes here -->
    </html>
    

    And now let’s look at the User controller and the login.php view:

    application/controllers/user.php

    class User extends Controller
    {
        function __construct() //this could also be called function User(). the way I do it here is a PHP5 constructor
        {
            parent::Controller();
        }
    
        function login()
        {
            $this->load->view('header.php');
            $this->load->view('login.php');
            $this->load->view('footer.php');
        }
    }
    

    application/views/login.php

    <div id="login_box">
    <!-- Put your login form here -->
    </div>
    

    And then finally the route to make /login look for /user/login:

    application/config/routes.php

    //add this line to the end of your routes list
    $routes['login'] = '/user/login';
    

    And that’s it. No magic or anything. The reason I brought up the fact that you can load views as strings is because you may not want to have separate “header” and “footer” views. In this case, you could simply “echo” out a view as a string INTO another view. Another example is if you have a shopping cart full of items and you want the shopping cart and the items to be separate views. You could iterate through your items, loading the “shoppingcartitem” view as a string for each item, concatenate them together, and echo that string into the “shoppingcart” view.

    So that should be it. If you still have questions, please let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sure. You don't say so, but I am assuming you… May 17, 2026 at 8:58 am
  • Editorial Team
    Editorial Team added an answer Two things to verify: Check the C runtime library DLL… May 17, 2026 at 8:58 am
  • Editorial Team
    Editorial Team added an answer What you're looking at is an opaque pointer or opaque… May 17, 2026 at 8:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need to create a cherrypy main page that has a login area. I
Is there anyway I can create a not in clause like I would have
I'm creating a calendar application in PHP with CodeIgniter. In the main calendar page,
I am currently building a website in codeigniter that is one page site, basically
I can create a menu item in the Windows Explorer context menu by adding
I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
I can create a literal long by appending an L to the value; why
In Postgresql you can create additional Aggregate Functions with CREATE AGGREGATE name(...); But this
this question can create a misunderstanding: I know I have to use CSS to
I want to know if i can create a custom google maps application,on which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.