Page 1 of 1
Why URL's need encoding?
Posted: Sun Aug 07, 2005 6:15 pm
by raghavan20
I dont really understand the importance of URL encoding? why is it done?
I understand the way its done but want to know why we have to do it and where it should be done?
Posted: Sun Aug 07, 2005 6:18 pm
by feyd
it helps avoid errors in the client's processing..
full of questions today, aren't we?
Posted: Sun Aug 07, 2005 6:25 pm
by raghavan20
jus developed a few applications; everything seem to be working fine until now. but I want to make sure I develop upto standards and use the best way when things can be done in different ways so I had to clear basic doubts atleast by now.
it helps avoid errors in the client's processing..
what do you mean by errors can come up during client's processing?
can you give me an example if you dont mind?
do we have to this when we normally pass links like
Code: Select all
echo "viewPost.php?action=viewPost&id=3";
do you say that I have to encode the above url in the php statement?
Posted: Sun Aug 07, 2005 6:35 pm
by feyd
certain parts require encoding when they contain non-standard characters, such as spaces, slashes, various other characters that may be accidentally thought as components of url's...
only the components should be processed... such as individual directory names, the filename, the keys and values of the query string, and possibly the hash..
Your example doesn't require it as it does not contain any mistakable characters.
Posted: Sun Aug 07, 2005 6:35 pm
by McGruff
raghavan20 wrote:do you say that I have to encode the above url in the php statement?
"viewPost" is OK because it contains only alphanumeric characters. If you were passing an unknown string via GET - such as a search term - it might contain anything and so you'd need to encode.
Posted: Sun Aug 07, 2005 7:30 pm
by josh
You should however replace & with &
This is to comply with the new xhtml standards, notice how when you place a copyright symbol, or a bullet in html you have to go &xxx; where xxx is an alphanumerica value, for example:
" for a quote
well when you output & in a url the clients web browser has to check wether or not you're trying to output a special html code.
Posted: Sun Aug 07, 2005 10:57 pm
by Roja
jshpro2 wrote:You should however replace & with &
This is to comply with the new xhtml standards
Thats an html standard, and its not new. It simply didn't cause user-agents to break until xhtml.
http://www.w3.org/TR/1999/REC-html401-1 ... ml#h-5.3.2
Its been around for 6 YEARS.

Posted: Mon Aug 08, 2005 12:08 am
by josh
Ahh, I didn't hear about it untill I started converting my pages to xhtml which caused me to think that... yeah...
Posted: Mon Aug 08, 2005 4:04 am
by onion2k
Imagine you want a user to submit a URL to your website, and your form is set to use GET.
The user submits:
http://www.ooer.com/index.php?section=php&id=2&page=2
Your url will end up being:
http://www.example.com/form.php?url=htt ... d=2&page=2
How would a anything reading that URL know where one begins and the other ends? By url encoding the GET request bit everythign is made clear.
Posted: Mon Aug 08, 2005 5:02 pm
by raghavan20
Alright!!! But if I gonna get a website link from a user. Then the user types in some link like the above you mentioned. Then if he clicks on the submit button it automatically gets appended to the url. I dont have a chance to really encode the url.
How do I do that, but I have a slight feeling that when variables are submitted through a form it automatically gets encoded???

Posted: Mon Aug 08, 2005 5:11 pm
by nielsene
Yes the browser (user-agent) will urlencode forms. However, if you're manually creating and GET-style URLs for navigation, etc, you should urlencode them yourself.