관련자료 : Ampersands in URI attribute values
http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2
GET방식으로 url 뒤에 (변수=값)을 덧붙여 다른 페이지로 값을 넘기고자 할때,
값 부분에 HTML엔터티[예를 들면 앰퍼샌드(&) 또는 물음표(?)]가 들어있는 경우 문제가 발생합니다.
이때 urlencode 함수를 이용하여 (변수=값)을 16진수로 변환.
변환된 값을 넘김으로써 url 파싱(해석)에 관련된 문제를 해결할 수 있습니다.
- PHP urlencode API
http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2
GET방식으로 url 뒤에 (변수=값)을 덧붙여 다른 페이지로 값을 넘기고자 할때,
값 부분에 HTML엔터티[예를 들면 앰퍼샌드(&) 또는 물음표(?)]가 들어있는 경우 문제가 발생합니다.
이때 urlencode 함수를 이용하여 (변수=값)을 16진수로 변환.
변환된 값을 넘김으로써 url 파싱(해석)에 관련된 문제를 해결할 수 있습니다.
- PHP urlencode API
PHPAPI char *php_url_encode(char *s, int len, int *new_length)
{
register int x, y;
unsigned char *str;
str = (unsigned char *) emalloc(3 * len + 1);
for (x = 0, y = 0; len--; x++, y++) {
str[y] = (unsigned char) s[x];
if (str[y] == ' ') {
str[y] = '+';
#ifndef CHARSET_EBCDIC
} else if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
(str[y] < 'A' && str[y] > '9') ||
(str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
(str[y] > 'z')) {
str[y++] = '%';
str[y++] = hexchars[(unsigned char) s[x] >> 4];
str[y] = hexchars[(unsigned char) s[x] & 15];
}
#else /*CHARSET_EBCDIC*/
} else if (!isalnum(str[y]) && strchr("_-.", str[y]) == NULL) {
/* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */
str[y++] = '%';
str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F];
}
#endif /*CHARSET_EBCDIC*/
}
str[y] = '\0';
if (new_length) {
*new_length = y;
}
return ((char *) str);
}
{
register int x, y;
unsigned char *str;
str = (unsigned char *) emalloc(3 * len + 1);
for (x = 0, y = 0; len--; x++, y++) {
str[y] = (unsigned char) s[x];
if (str[y] == ' ') {
str[y] = '+';
#ifndef CHARSET_EBCDIC
} else if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
(str[y] < 'A' && str[y] > '9') ||
(str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
(str[y] > 'z')) {
str[y++] = '%';
str[y++] = hexchars[(unsigned char) s[x] >> 4];
str[y] = hexchars[(unsigned char) s[x] & 15];
}
#else /*CHARSET_EBCDIC*/
} else if (!isalnum(str[y]) && strchr("_-.", str[y]) == NULL) {
/* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */
str[y++] = '%';
str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F];
}
#endif /*CHARSET_EBCDIC*/
}
str[y] = '\0';
if (new_length) {
*new_length = y;
}
return ((char *) str);
}