CodeIgniter Forums
permitted_uri_chars and $_GET - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: permitted_uri_chars and $_GET (/showthread.php?tid=6007)

Pages: 1 2 3 4 5


permitted_uri_chars and $_GET - El Forum - 02-11-2008

[eluser]ooskar[/eluser]
hi,
i have CI with default config.
my question is:
how can i use url like this http://www.mysite/controller/action/?val=1&val=2

now i see error "page not found"


permitted_uri_chars and $_GET - El Forum - 02-11-2008

[eluser]Michael;[/eluser]
Try this link:

http://ellislab.com/codeigniter/user-guide/general/security.html


permitted_uri_chars and $_GET - El Forum - 02-11-2008

[eluser]Edemilson Lima[/eluser]
You can use segments or query strings, but not both, I think. To enable query strings, open your config/config.php and change this line to TRUE:
Code:
$config['enable_query_strings'] = FALSE;
If you enable query strings, your URL will become:
Code:
www.yoursite.com/index.php?c=controler_name&m=function_name&other_var=value
Is much better to use segments than query strings, because is more search engine friendly, more readable and more secure. By default, CodeIgniter clear the $_GET array when query strings are disabled, for security reasons.


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]ooskar[/eluser]
but i need use standard controller and $_GET together.

this http://www.mysite/controller/action/?val=1&val=2


and now i i add "?val=1"
CI say "page not found"

i tried add "?" to permitted_uri_chars but it doesnt works

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


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]Edemilson Lima[/eluser]
Code:
http://www.mysite/controller/action/?val=1&val=2
When you try this, CodeIgniter will consider the "?val=1&val=2" as a third segment and try to pass it as a parameter to your "action" function. The best way to do this is:
Code:
http://www.mysite/controller/action/1/2
Where 1 and 2 will be the values passed to the function. Your controller could be:
Code:
class Test extendes Controller {

  function index() {
    // default function
  }

  function action($val1,$val2) {
    echo 'Value 1 = ',$val1,'<br />';
    echo 'Value 2 = ',$val2;
  }

}
So, if you call the address "http://www.mysite.com/test/action/123/456", it will display:

Value 1 = 123
Value 2 = 456

As I said before, this way is more search engine friendly, more readable and more secure.


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]ooskar[/eluser]
but i need use ?val=1 not as function's params but in javascript

i need permit "?" in url
i dont use $_GET parameters on my website

i cant change js because it is from other company


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]Edemilson Lima[/eluser]
Hmmmm... I don't know if it is possible to use URI segments and query strings together. You could enable the query strings ($config[’enable_query_strings’] = TRUE), but in this case you need to build your URLs as I said (www.yoursite.com/?c=controler_name&m=function_name&par1=value&par2=value).

I think the regular expression below is wrong. If you want to alow the hifem "-" in your URI, you must put it in the end of the string.
Code:
$config[’permitted_uri_chars’] = ‘a-z 0-9~%.:_-?&=’;
The regular expression above will consider the ASCII characters from "_" to "?".


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]ooskar[/eluser]
so, how should look $config[’permitted_uri_chars’]?

$config[’permitted_uri_chars’] = ‘?&=a-z 0-9~%.:_-’; doesnt work


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]Edemilson Lima[/eluser]
Try this:
Code:
"a-z 0-9~%.:_\?&=-"
I am not sure if is the case here, but the question mark "?" is a special character in regular expressions. It makes the expression to "ask" if the caracter before it exist or not in the string. If you need to use any special character as a normal character, you must escape them with a "\".


permitted_uri_chars and $_GET - El Forum - 02-12-2008

[eluser]ooskar[/eluser]
i try it yesterday but CI crashed.