Hot File

People make multiple manual website in codeigniter with same code and database dynamically

View: 436    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Codeigniter   Fields: Other

0 point/2 review File has been tested

I hope you are little bit faimliear with multiple website

Introduction

I hope you are little bit faimliear with multiple website

.In multiple website we create the subdomain of the website and use the same database and same code structure for all the subdomain.

We must want to use same codebase, database. Only the subdomain different.

For that first you need to contact your hosting provider and need to activate multiple website functionality on your website.

Now create a table in your database where we will insert the subdomain data using form.

CREATE TABLE IF NOT EXISTS `subdomains` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `subdomain_name` varchar(100) NOT NULL,
 `email` varchar(50) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Now create a view to insert the subdomain name in the database and insert data in your subdomain table dynamically. I hope you already know how to insert data in database in codeigniter.So here I will not write down the code to insert the subdomain data in database.
If you don’t know how to insert data in database in codeigniter please read this tutorial
how to insert data in database in codeigniter

Now you need to make the base_url dynamic in config.php file.
open config.php file and replace your base_url to

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"){$ssl_set = "s";} else{$ssl_set = "";}
$config['base_url'] = 'http'.$ssl_set.'://'.$_SERVER['HTTP_HOST'];

Now run your main domain http://www.example.com this will redirect you to the your main site.

to check the subdomain is it registered or not in your database you have to do some coding in your controller.

when your first controller run(the controller you have set default controller in your route.php file).
Lets Mycontroller is your default controller.

write this code in the controller construct function so we can check before running any function that the subdomain is available or not in your database

db->from('subdomains')->where('subdomain_name', $subdomain_name);//now check for the subdomain if it is available
        $query = $this->db->get();
        if($query->num_rows() < 1)
        {
        //redirect ('make error page to show domain name not avalable');//if there is no result in your database show the error to user that subdomain
        //is not available
        echo "domain name not registered";
        }
    }
     function index()
    {
        $subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2);
        $subdomain_name = $subdomain_arr[0];
         
        $this->db->from('subdomains')->where('subdomain_name', $subdomain_name);
        $query = $this->db->get();
        $subdomain_info = $query->row();// here you will get the subdomain information
         Print_r($subdomain_info);
         echo "domain registered";
    }
}

Now add data in your table (make a form to insert the subdomain data in database. ).
For example you have entered domain name demo1 in table as subdomain name.
Now run http://www.demo1.example.com,

If the subdomain is available in database then your function will run and it will get data according to your domain name and print it.If domain name not found it will redirect you to error page that domain name is not available.
Please note that you need to save the subdomain ID in each table to differentiate the data of each subdomain later on.

Hope this article how to make multiple website(subdomain of your main site) in codeigniter with same code and database dynamically will help you.Feel free to ask any question.
You can email me to get the complete code how multiple website work in codeigniter. Keep reading. cheers!

People make multiple manual website in codeigniter with same code and database dynamically

People make multiple manual website in codeigniter with same code and database dynamically Posted on 08-01-2016  I hope you are little bit faimliear with multiple website 5/10 436

Comment:

To comment you must be logged in members.

Files with category

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd