2015-10-19 20 views
1

我想爲我的網站編寫一個簡單的密碼系統。沒有用戶名,沒有這樣的,只是我可以分發給朋友的密碼。我們的想法是一個值傳遞給寫在C以下的小CGI程序:CGI的問題不能根據HTML表單輸入返回正確的響應

#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」,但它仍然打印「拒絕」。我很確定我正確地做了這件事,我不知道這是否是服務器問題(TinyWeb)。 HTML表單代碼如下:

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

回答

1

在C中,不能使用==比較字符串。使用strcmp