php CodeIgniter current_url 不显示查询字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4160377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter current_url doesn't show query strings
提问by michael
Hi I'm trying to store my current url in a session variable.
嗨,我正在尝试将我当前的 url 存储在会话变量中。
My app uses query strings like www.domain.com/add?url=http://www.google.com
我的应用程序使用查询字符串,如 www.domain.com/add?url=http://www.google.com
but current_url() returns 'ww.domain.com/add'. The url without the query strings.
但 current_url() 返回 'ww.domain.com/add'。没有查询字符串的 url。
I've checked the helper file and current_url seems to just append the uri segments to the site_url set in the config.
我检查了帮助文件,current_url 似乎只是将 uri 段附加到配置中设置的 site_url。
function current_url()
{
$CI =& get_instance();
return $CI->config->site_url($CI->uri->uri_string());
}
anyone know how I can grab the query strings to append them, or even just grab the whole url.
任何人都知道我如何抓取查询字符串来附加它们,甚至只是抓取整个 url。
回答by Phil Sturgeon
Create a MY_url_helper:
创建一个 MY_url_helper:
function current_url()
{
$CI =& get_instance();
$url = $CI->config->site_url($CI->uri->uri_string());
return $_SERVER['QUERY_STRING'] ? $url.'?'.$_SERVER['QUERY_STRING'] : $url;
}
回答by Mischa
I don't think CodeIgniter has any helpers for this. Just use PHP's native support for this:
我不认为 CodeIgniter 对此有任何帮助。只需使用 PHP 的本机支持即可:
Echo the full URL:
回显完整的 URL:
echo base_url().ltrim($_SERVER['REQUEST_URI'], '/');
Only the query strings:
只有查询字符串:
echo $_SERVER['QUERY_STRING'];