Welcome Guest, Not a member yet? Register   Sign In
CIiBug? Url Encode /Url Decode problem in url Query Strings
#1

[eluser]mindprojects[/eluser]
Hy guys i have this problem and i don't know if it's a CI Bug.
For SEO purposes and pagination, when i'm searching something in my app,my url will appear something like:
CONTROLLER/METHOD/CLEAR_PARAMS

1) If you are searching "test app" ,i send this post string to the same controller and the i redirect to the same page for pagination purposes doing an URLENCODE so that i see something like:

CONTROLLER/METHOD/q/test+app


Then in my controller if i want to get the search string i'm doing:
URLDECODE($this->uri->segment(4); and i get "test app".

The problem happens in this case:
I'm searching for "test + app" (plus is into the string for fulltext purposes).
Then in my controller i URLENCODE this post string and i redirect to the same page
for pagination purposes and i see something like:

CONTROLLER/METHOD/q/test+%2_B+app

Now if i want to get the search string i'm doing:
URLDECODE($this->uri->segment(4); and i get "test app" again.NO PLUS SIGN AT ALL!!!!

Is it a router.php problem ,in which i've seen the $_SERVER['PATH_INFO'] is used to retrieve the query string?
How can i solve this problem?

Thanks in advance
#2

[eluser]rogierb[/eluser]
Dude, why post in two forums? And why the CAPS?

Check if you have global xss filtering on.
#3

[eluser]mindprojects[/eluser]
It was en error,if you read at the first post,i replied immediately.
I've checked that xss filtering is OFF.
Any solutions?
#4

[eluser]sophistry[/eluser]
you want:

http://php.net/rawurlencode

regular urlencode() function turns spaces to plus characters.
#5

[eluser]mindprojects[/eluser]
Thanks, but now i can see into the url something like spaces instead of plus signs!
Using an input box to submit a string i have:

1)rawurlencode(a + b) => into the url i can see : a %2_B b
INPUT TEXT RESULT(doing rawurldecode($this->uri->segment(x))) : a + b


2)urlencode(a + b) => into the url i can see : a+%2_B+b
INPUT TEXT RESULT(doing urldecode($this->uri->segment(x))) : a b

I would like to do something like in ebay:
Into the searchbox type a + b:

URL RESULT: =a+%2_B+b& (it uses urlencode)
INPUT TEXT RESULT : a + b (do they urldecode or using GET directly ?)

If i use GET,like in this thread http://ellislab.com/forums/viewthread/99570/ it works without urldecode, but they say that setting PATH INFO in your config,your app may not work on all servers.
#6

[eluser]sophistry[/eluser]
i don't understand why example #1 does not work. perhaps because you used the word "into" which is not the right word in english and it is causing some ambiguity. for example if i type the sentence:

"i put the word into the URL" that means that i typed the word in the URL address bar.

maybe you mean this:

"i used rawurlencode on the string that i output to the browser" using "on" here to indicate that the function is operating on the string.

please clarify.

also, it seems like you might actually want the rawurldecode() function... if you are handling form inputs.
#7

[eluser]mindprojects[/eluser]
A better explanation:

1) i have an input text into a form(name='q')
2) i submit the form after typing 'a + b', to the same controller
3) if the validation run === TRUE then i build my new url and redirect to this url.
To send the string i need to urlencode/rawurldecode,so that i do:

urlencode(a + b)

Then i redirect to :
controller/function/q/a+%2_B+b (to avoid the refresh multiple post problem)

4)Into the destination controller to get the parameter i do
urldecode($this->uri->segment(4),but i can get only 'a b'(not plus at all)

I found a solution here using GET!
http://ellislab.com/forums/viewthread/56389/#277621,but i can't understand why it's not working by the uri segment way.
#8

[eluser]sophistry[/eluser]
ok, much clearer now (but you are still using the word "into" wrong - i think you mean to use the english word "in")... "into" is used to describe an action (e.g., "i put the duck into the garbage" is OK - emphasizes the action), it's a little confusing because "in" can also be used to describe an action (e.g., "i put the duck in the garbage" is OK - emphasizes the duck's location) but "in" is also used to describe a state of something (i.e, where it is located). "into" is never used to describe a state or location of a thing. so, your sentence: "i have an input text into a form" is not OK. the correct word is "in": "i have an input text field in a form" is OK.

in step #3 rawurlencode('a + b') should give you a string like (EDIT - forum is changing percent sign HEX codes):
Code:
a%2_0%2_B%2_0b (hex with underscores)

does it give you that string? that's the string i see when i do this:

EDIT - added controller code
Code:
function encode_test($s)
{
print_r(rawurlencode('a + b'));
print_r(rawurlencode($s));
print_r(rawurlencode($this->uri->segment(3)));
print_r(rawurldecode($this->uri->segment(3)));
}
#9

[eluser]mindprojects[/eluser]
Sorry,about my english,it's not so good sometimes...
Now using rawurlencode,to get the string i do :
Code:
echo rawurldecode($this->uri->segment(3)) and
i get a + b written in(:-))the right way.

The problem is that when i'm searching for 'a + b' ,using rawurlencode at point 3,i get (looking at the firefox browser url):
Code:
a %2_B b  (no %2_0 at all)
I see white spaces!
By the other way if i'm printing $this->uri->segment(3) inside my controller i can see:
Code:
a%2_0%2_B%2_0b

Is it possible to have white spaces in the url?
#10

[eluser]sophistry[/eluser]
hey, your english is very good - it's just that the word "into" was confusing me so i went all pedagogical on you! besides, your english is WAY better than my italian.

maybe the browser is not showing the hex codes and just converts them in the address bar.

when i use rawurlencode and do a redirect it properly encodes the data and does the redirect.




Theme © iAndrew 2016 - Forum software by © MyBB