Get query string on FastCGI using C

0
9207
FastCGI
FastCGI

Query string is the fragment that is the literal string after the question mark on an URL.

For example, in following URL, http://blog.petehouston.com/api/posts?sort=desc&category=featured , the part sort=desc&category=featured is the query string.

On FastCGI, you can get query string via QUERY_STRING environment variables. So, you will need to use getenv() method to retrieve the value.


char *get_query_string()
{
    char *query_string = getenv("QUERY_STRING");
    if(!query_string) {
        query_string = "";
    }
    return query_string;
}

That’s it!