开发者

Changing Form Action Location in CodeIgniter

I am writing a web application using Codeigniter for a client and am using one of their internal development machines. Due to security restrictions the web server port is only internal and not exposed to the outsi开发者_开发百科de world so I must access it over a SSH tunnel. So I hit the web server like this: http://localhost/path_to_data.

I am creating a form in Codeigniter using the standard Form Helper, the only problem is that the form's action is pointed at the location of the box from the Codeigniter config file. I cannot change this config value because we have internal developers that access this as well that won't use a SSH tunnel so they hit it by the "real" URL.

Is there a way to force Codeigniter to use the form to point at itself with a relative path instead of the full path?


form_open() uses the base url set in config.php: $config['base_url']. Try making it conditional, based on $_SERVER['SERVER_NAME']. That way both the internal developers using, say, "http://demo.local", as well as you using "http://localhost/" will be able to see the proper absolute urls, based on how they're accessing the server.

$config['base_url'] = 'http://demo.local/' ;
if ($_SERVER['SERVER_NAME'] == 'localhost') {
    $config['base_url'] = http://localhost/' ;
}

As a sidenote, I notice that form_open() checks if the passed parameter is a full url (specifically if it includes a "://" ), and if it does then it sets it as the form's action without any processing. So you could be calling form_open("http://localhost/form_submit") and having it be used as is without the base_url.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜