简体   繁体   中英

How to use a C CGI program to send the user to a URL at the end of the program

I have a CGI program in C and it is suppose to accept input from HTML form tag, which it can do but then after it gets the data from the form tag it will check if user credentials is valid. After it is validated, how would I use the CGI to send me to another webpage.

I have tried just printing out the html which works as well but doesn't seem like the right way to do it. Thanks.

CGI doesn't care that your program is written in C or anything else; the method for redirecting is the same. Set the status code to "302" (or 303), and include a Location header specifying the new webpage.

The simplest version of the code would be something like:

fprintf(stdout,"%d %s\r\n",302,"Redirect");
fprintf(stdout,"%s: %s\r\n","Location","/newpage");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM