CGI 未根据 HTML 表单输入返回正确响应的问题

Issue with CGI not returning correct response based on HTML form input

我正在尝试为我的网站编写一个简单的密码系统。没有用户名,没有类似的东西,只有我可以分发给朋友的密码。思路是给下面用C写的CGI小程序传一个值:

#include <stdio.h>
#include <stdlib.h>
int main(){
char *test;
printf("Content-Type: text/html\n\n");            //give the content type
test = getenv("QUERY_STRING");                    //get the data
//printf ("%s\n\n", test);                        //print it for debugging purposes
if (test == "test=test") {                        //check for correct password
    printf("<a href=\"home.html\">Enter.</a>");   //give the link if correct
}
else if (test == NULL){
    printf("Error.");
}
else{
    printf("Denied.", test);
}
return(0);
}

问题是,无论传递给它什么,它总是打印 "Denied"。每当我打印返回的数据时,它正是我所期望的,即 "test=test",但它仍然打印 "Denied"。我很确定我这样做是正确的,我想知道这是否是服务器 (TinyWeb) 的问题。 HTML 表单代码如下:

<form action="cgi-bin/cgi.exe" method="get">
    <input name="test" placeholder="Password">
    <input type="submit" value="enter">
</form>

在 C 中,您不能使用 == 比较字符串。使用 strcmp.