For some reason when I access this function I only can use it once and then if I try to access it again it doesn't work (When using this querystring: name1=value1&name2=value2).
It seems that the function is continuing from when it was previously accessed.
Code:
int main(int argc, char *argv[]) {
printf("HTTP/1.1 200 OK\n");
printf("Content-Type: text/html\n\n");
printf("%s<br />", QueryString("name1"));
printf("%s<br />", QueryString("name2"));
return 0;
}
char *QueryString(char *strobj) {
if (getenv("QUERY_STRING")) {
if (strstr(getenv("QUERY_STRING"), strobj)) {
char *word;
boolean strtype = TRUE;
int stropt = 0;
word = strtok(getenv("QUERY_STRING"), "&=");
while (word) {
if (strtype == TRUE) {
if (strstr(word, strobj)) {
stropt = 1;
}
strtype = FALSE;
} else {
if (stropt == 1) {
return ("%s", word);
break;
}
strtype = TRUE;
}
word = strtok(NULL, "&=");
}
} else {
return "";
}
} else {
return "";
}
}
Does anyone know why this would be happening and how I can fix this?