Get url so can send it in an email - codeigniter

I need to get the url and place it in my code so it can be sent has a link in an email.
SO if i have localhost/interiors/accessories/clocks/mantle-clocks/mantle-clock
I need to get this url so i can place it my controller to send it as an email link.

Use the $_SERVER global. It should contain the information you need, e.g. REQUEST_URI etc

Your problem is pretty simple you can call current_url() helper method of Codeigniter
$url = current_url();
Use this url to send in email. Or if this is not what you want than you will have to manually generate url.
$url = http://localhost/interiors/accessories/clocks/mantle-clocks/mantle-clock';

Related

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`

Redirect to external website in Laravel without adding http(s)://

My web app needs to redirect user to an external website using
redirect()->away($url).
However, this won't work if url does not contain "http://" or "https://". Because the url is user defined, I don't think it's a good way to manually add "http://" or "https://". Is there any way in Laravel that can be used to redirect user to external website without need to add "http(s)://"?
There is nothing in Laravel that will force the $url passed to away() to be an external url. Using away() is so Laravel doesn't force it to be an internal url.
You can use parse_url to check if the HOST portion exists. If it does, it is an absolute URL and will redirect as you expect. If it doesn't, add a '//' to the beginning of the redirect url, so it will redirect away.
redirect()->away((is_null(parse_url($url, PHP_URL_HOST)) ? '//' : '').$url);
Note, check the HOST, and not the SCHEME. If the user enters `//google.com', this is correct and will redirect as expected, but the scheme is empty.
Or, as #Thomas suggests, use validation to force the user to enter an absolute url.
Yes, force the user to enter it with a simple regex validation rule: 'url' => 'regex:#^https?://#'.

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.

How do i redirect my all old url to new url Codeigniter

I want to redirect my all old url to new url.
My few old URLs are
domain.com/
domain.com/submit
domain.com/get/soft-name
domain.com/most-downloaded
etc, etc,
Now i want to redirect my all url to
domain.com/en
domain.com/en/submit
domain.com/en/get/soft-name
domain.com/en/most-downloaded
I am using CodeIgniter. Please Suggest me some code for route.php
thanks in advance
If you want to handle this in your routing, you could just do this:
$route['(:any)'] = "en/$1";

Resources