Why URL's need encoding?
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Why URL's need encoding?
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?
I understand the way its done but want to know why we have to do it and where it should be done?
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
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.
can you give me an example if you dont mind?
do we have to this when we normally pass links like
do you say that I have to encode the above url in the php statement?
what do you mean by errors can come up during client's processing?it helps avoid errors in the 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";- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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.
"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.raghavan20 wrote:do you say that I have to encode the above url in the php statement?
Last edited by McGruff on Mon Aug 08, 2005 3:16 pm, edited 1 time in total.
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.
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.
Thats an html standard, and its not new. It simply didn't cause user-agents to break until xhtml.jshpro2 wrote:You should however replace & with &
This is to comply with the new xhtml standards
http://www.w3.org/TR/1999/REC-html401-1 ... ml#h-5.3.2
Its been around for 6 YEARS.
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.
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.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
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.onion2k wrote: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.
How do I do that, but I have a slight feeling that when variables are submitted through a form it automatically gets encoded???