gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:35:19 26 4
gpt4 key购买 nike

我正在尝试为我的网站编写一个简单的密码系统。没有用户名,没有类似的东西,只有我可以分发给 friend 的密码。这个想法是将一个值传递给下面用 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);
}

问题是,无论传递给它什么,它总是打印“拒绝”。每当我打印返回的数据时,它正是我所期望的,即“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

关于html - CGI 未根据 HTML 表单输入返回正确响应的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33205005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com