Encrypt URL with PHP Codeigniter - 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`

Related

Yii2 how to rewrite url without controller name

I am rewriting my yii2 website urls.In my config file i added
'<category_name>-<controller>-<category_id>'=>'<controller>/index'
and in the url i just passed the parameters like
<?=Url::to(['shop/index','category_id'=>1,'category_name'=>'clothes'])?>
And my url comes like
https://example.com/clothes-shop-1
This is what i am getting. But i need something like
https://example.com/clothes-1
for that i just changed the rule like this
'<category_name>-<category_id>'=>'<controller>/index'
But that time rewriting doesn't working.How can i remove the controller name from that url
How does system know, what controller is needed to proceed URL? In first example
'<category_name>-<controller>-<category_id>'=>'<controller>/index'
There is a controller name. In second
'<category_name>-<category_id>'=>'<controller>/index'
No controller name.
So you need to tell it. Try
'<category_name>-<category_id>'=>'shop/index'

How to load an codeigniter application by using different url

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

Routing problems, CodeIgniter

This might be a very silly question because I'm new to PHP frameworks. But I have got the concept of MVC framework. But this routing thing is very confusing me.
I created a controller and view for dashboard and set it as default. Then I wanted to check if the user is logged in then send him to the login page if it's not.
So, what I did in the routes is this:
$route['default_controller'] = 'dashboard/index';
$route['login'] = 'login';
But even if I add a thousand more controllers and routes, it still goes to the default i.e the dashboard. This was supposed to work http://localhost/codeigniter/login. I'm very sure I haven't put a redirect-to-dashboard code in the login page.
at first it's important to understand to routing in codeigniter.
The key for understanding is $route['url/path'] = controller/method (or "public function")
So. In your case, you routing to Login controller and index method (or index function...this it interpretation of codeigniter )
If you want to check if is user logged or not, you may try to check for examle session variable inside of called functon. But it depends on your application. But I think that is not good idea to check it in routes.php
Hope it helps you.
The default controller in routes, will be the controller that opens your index or first page.
If your first page is in controller "pages", then that is your default controller. Do not use it for your secure dashboard pages
Your first page should be the index method in the controller. It should look like this
$route['default_controller'] = "pages";
Where pages is your first page controller

Codeigniter custom URL Routing

I have a URL in my Codeigniter
http://localhost:64743/index.php/mybox?name=John
I want it to look something like this
http://localhost:64743/index.php/mybox/name/John
is it posiible? how does custom URL works in CodeIgniter?
$route['mybox/(:any)'] = "mybox/index";
user above mention code in routes.php of config folder and you will get query string value by $this->uri->segment(3); and $this->uri->seggment(4);
for further assistance, please check
https://ellislab.com/codeigniter/user-guide/general/routing.html

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.

Resources