php CodeIgniter $this->input->get() 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14046884/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:30:30  来源:igfitidea点击:

CodeIgniter $this->input->get() not working

phpcodeigniter

提问by KraigBalla

I'm not sure why this is not working. I have allow_get_array = TRUE in the config file. Here's what I am trying to do..

我不确定为什么这不起作用。我在配置文件中有 allow_get_array = TRUE 。这就是我想要做的..

This is the link that the user will click from their email

这是用户将从他们的电子邮件中点击的链接

http://www.site.com/confirm?code=f8c53b1578f7c05471d087f18b343af0c3a638

confirm.php Controller:

confirm.php 控制器:

$code = $this->input->get('code');

also tried

也试过

$code = $this->input->get('code', TRUE);

Any ideas?

有任何想法吗?

采纳答案by KraigBalla

I did this and it worked without having to change the config file:

我这样做了,它无需更改配置文件即可工作:

//put some vars back into $_GET.
parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);

// grab values as you would from an ordinary $_GET superglobal array associative index.
$code = $_GET['code']; 

回答by PhearOfRayne

In your config.phpchange the following:

在您的config.php更改中:

$config['uri_protocol'] = 'AUTO';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;

To:

到:

$config['uri_protocol'] = 'REQUEST_URI';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';
$config['enable_query_strings'] = TRUE;

Instead of messing with Query Strings you could change your URI to use segments like http://www.site.com/confirm/code/f8c53b1578f7c05471d087f18b343af0c3a638. To access the code segment you would use $this->uri->segment(3);. Personally I prefer this way as to using Query Strings. See URI Class

您可以更改 URI 以使用像http://www.site.com/confirm/code/f8c53b1578f7c05471d087f18b343af0c3a638. 要访问代码段,您将使用$this->uri->segment(3);. 我个人更喜欢这种方式来使用查询字符串。请参阅URI 类

回答by Silvio Delgado

Use this:

用这个:

$code = isset($_REQUEST['code']) ? $_REQUEST['code'] : NULL;

EDIT:

编辑:

In PHP >=7.0, you can do this:

在 PHP >=7.0 中,你可以这样做:

$code = $_REQUEST['code'] ?? NULL;

回答by itsme

can you please try

你能试试吗

http://www.site.com/confirm/?code=f8c53b1578f7c05471d087f18b343af0c3a638

instead of

代替

http://www.site.com/confirm?code=f8c53b1578f7c05471d087f18b343af0c3a638

without any config or else edit please

没有任何配置,否则请编辑