How to load an codeigniter application by using different url - codeigniter

Now I am developing an application by using CodeIgniter framework. In this application, there is a section which name account setup. By using this section we can create multiple accounts. As an example, accounts name are abc, bca or anything. And Suppose my site URL is: www.xyz.com (base_url) Then we need to access the site by the domain name and also domain name with account name like bellow:
www.xyz.com
www.xyz.com/abc/
www.xyz.com/bca/
www.xyz.com/anything/
For More clear, URL pattern will be:
www.xyz.com/dashboard/index
www.xyz.com/abc/dashboard/index
www.xyz.com/bca/dashboard/index
How can we do it? I need your suggestion.

Yes it's Possible through codeigniter Routs.
Go to application\config Open a file which Name is routes.php
you can call the controller functions see in code example
example
$route['new_project'] = "controller/function";
when you hit your website url like this www.xyz.com/new_project it will go to your mention controller and function.
see the documentation of routs CodeIgniter URI Routing
example 2:
$route['account/(.*)'] = "controller/function";
Now we you redirect your url like this
redirect('account/'.$name_var.'');
Now your url look like this.
www.xyz.com/account/name_of_logged_in_user
Also you can use this like this.
$route['(.*)/dashboard/index'] = "controller/function";
And then you can call it like this.
redirect(''.$name_var.'/dashboard/index');
And from this code your output url show something like this.
www.xyz.com/name_of_logged_in_user/dashboard/index
Hope it will help you if any question add comment

There are many way to do it.
1) Domain alias if you want to run same script with different domain.
2) if you want to run same script with sub domain then you can do it from Cpanel
3) If you want to run same script with different folders in same domain then you need to use htaccess

Related

Laravel subdomain route problame

I am working on a subdomain system on laravel.
suppose my main domain name is: test.test
and my subdomain name is: subdomain.test.test
Now, the problem is, when I use the main domain route in sub-domain blade file like:
Profile
then, it should generate links like test.test/profile
but, it's generating links with subdomain like: subdomain.test.test/profile
Now, How can I solve this problame?
An alternative would be to use relative path instead of absolute using route() helper third parameter.
Profile
I recommend you to use Spatie Multitenancy, when i do route('home'), he return back the url with the actual domain.

Encrypt URL with PHP Codeigniter

I have developed a website with PHP Codeigniter. It consists of many controllers and views. I want to encrypt the URL of the site to hide the controller and function name. Currently, the URL looks like this :
www.sitename.com/controller_name/function_name
I don't want the users to see the controller and function names. Is it possible to do this now because the site is almost complete. Is there any shortcut of doing this? Please Help
You can use codeigniter URI Routing to remove your controller name from URL.
$route['url_name'] = 'controller_name/function_name';
This `www.sitename.com/url_name` will look go to `www.sitename.com/controller_name/function_name`
$route['url_name/(:any)'] = 'controller_name/$1';
This will only change your controller name.. `controller_name` to `url_name`

how to make sub folder for login page and rest of the pages in codeigniter

I am working in a codeigniter project in wamp server.
My current login page is http://localhost/flowers/login and its working correctly (no issue). The rest of the urls are like this
http://localhost/handycheck/admin/dashboard etc
My issue is i need to change the login url like this
http://localhost/flowers/admin/login
&
http://localhost/flowers/providers/login
Its because I have to maintain login form for multiple users.
How can i make this.
Please help me and thanks in advance who helps me alot..
You can do this by adding custom roue in codeigniter routing configuration as follows go to config/routes and add the following entry in this file
$route['flowers/providers/login'] = 'flowers/login';
$route['flowers/admin/login'] = 'flowers/login';
this will redirect the request to the login in flowers controller and if you need to do custom handling for admins and provider you can get the url segments and do custom handling according to user type
I hope my answer would be useful

Codeigniter - Htaccess : How to change a controller name

This is my first question here, so Hi all! ^^
I created a website with codeigniter framework and I have inserted a module for multilanguage. The url looks like this:
http://www.mywebsite.com/en/controller/function
The problem came when the client wanted to send a newsletter to all its customers in another language, but do not want to send the url with the controler with the name in english, because the newsletter is for spanish users.So:
URL is going to be send:
http://www.mywebsite.com/es/thecontroller
URL the client wants to be send ("elcontrolador" is "thecontroler" in spanish):
http://www.mywebsite.com/es/elcontrolador
I dont want to create another controler named "elcontorlador" only to show the same page as "thecontroler", because we don't want duplicate content for SEO purposes.
So, i want via .htaccess, a rule that when i type
http://www.mywebsite.com/es/elcontrolador
in the URL, mywebpage shows the info of
http://www.mywebsite.com/es/thecontroler
but with the URL
http://www.mywebsite.com/es/elcontrolador
(the controler "elcontrolador" doesnt exist).
So, is there any way to do this with the htaccess? I've tried it myself but I failed miserably i come here desperate, because I run out of time to deliver it and can not find a viable solution. I'll have to create the extra controller?
Need help D:
Maybe you can use the route config file instead to achieve this ?
$route['es/elcontrolador'] = 'es/thecontroler';
I don't know how you handle your multilangage, but you've got the idea.

How do I change the index page in a CodeIgniter anchor?

So, I have two different applications in my CodeIgniter installation. One is admin, the other is frontend. I basically just copied the index file, renamed it "admin.php", and changed the application directory to "application/admin". I then changed the application directory in index.php to "application/frontend".
What I would like to do is create a link on the frontend application that takes you to the admin application. The variable config['index_page'] in the frontend application is set to "index.php" and in the admin application it's set to "admin.php".
Is there a way to set the url helper to use "admin.php" instead of "index.php"?
You don't need to do that way.
you should make or use an authentication library and you set different roles for different
users.
you just after login can put the redirection to your admin controller.
and for other users and viewers you can redirect them to any other controllers.
for viewers you can just use something like this:
Code:
if(!$this->m_auth->is_logged_in())
{
$this->viewers();
}
else
{
$this->users();
}
In your users function you just check different roles and redirect according.
I think you are missing some codeigniter concept, and you are trying to do it the normal way, i suggest you to read this article , you will how you can use MY_Controller as same concept of front controller and how you will be able to give every use specific roles
another way is to use a ready made authentication library as #medhi said
I would recommend Tank Authentication or Ion Auth
I

Resources