Welcome Guest, Not a member yet? Register   Sign In
redirect url helper redirect to localhost
#11

(05-08-2015, 01:53 AM)rtorralba Wrote: Hi,

When a call a redirect url helper function this function as following:

redirect('controller/method');

redirect to http://localhost/index.php/controller/method

If I set base_url variable on config file works correctly and redirect to http://myvirtualhost.com/index.php/controller/method but this not was necessary on codeigniter 2 and can be a problem because we must to define a base_url per environment.

Greetings.

Hi rtorralba,

if i not get you wrong, what you mean is without define base_url is only working for CI 2 but not for CI 3. So i guess what you want is a dynamic base_url. 

What you can do is.. 


PHP Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 

update this base_url, this script will auto help you defined base_url and even work in localhost.
Reply
#12

(05-13-2015, 07:19 PM)Edwin Wrote:
(05-08-2015, 01:53 AM)rtorralba Wrote: Hi,

When a call a redirect url helper function this function as following:

redirect('controller/method');

redirect to http://localhost/index.php/controller/method

If I set base_url variable on config file works correctly and redirect to http://myvirtualhost.com/index.php/controller/method but this not was necessary on codeigniter 2 and can be a problem because we must to define a base_url per environment.

Greetings.

Hi rtorralba,

if i not get you wrong, what you mean is without define base_url is only working for CI 2 but not for CI 3. So i guess what you want is a dynamic base_url. 

What you can do is.. 



PHP Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 

update this base_url, this script will auto help you defined base_url and even work in localhost.

This is worse than leaving it blank ... it ignores security checks.
Reply
#13

(05-13-2015, 07:19 PM)Edwin Wrote:
(05-08-2015, 01:53 AM)rtorralba Wrote: Hi,

When a call a redirect url helper function this function as following:

redirect('controller/method');

redirect to http://localhost/index.php/controller/method

If I set base_url variable on config file works correctly and redirect to http://myvirtualhost.com/index.php/controller/method but this not was necessary on codeigniter 2 and can be a problem because we must to define a base_url per environment.

Greetings.

Hi rtorralba,

if i not get you wrong, what you mean is without define base_url is only working for CI 2 but not for CI 3. So i guess what you want is a dynamic base_url. 

What you can do is.. 



PHP Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 

update this base_url, this script will auto help you defined base_url and even work in localhost.

I already knew, but the question was why in ci 2 it was not necessary and in ci 3 is necessary.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB