繁体   English   中英

C / HTML:正确打印用户名和密码输入

[英]C/HTML: Correctly printing the username and password input of the user

几天前,我开始尝试使用C / CGI / HTML。 我被看到的某些登录页面程序激怒了,所以我尝试自己做:

这是我的程序:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
  char *data;
  char *user;
  char *password;
  printf("Content-type:text/html\r\n\r\n");
  printf("<!DOCTYPE html><html><head><title>Hello</title></head><body>");
  data = getenv("QUERY_STRING");
  if (data) {
    sscanf(data,"user=%s&password=%s", user, password);
    printf("Hello Mr./Ms. %s\n",user);
    printf("You entered your password %s\n",password);
  }
  printf("<form action='http://localhost/10.html'>");
  printf("<input type=text name=user>");
  printf("<input type=password name =password>");
  printf("</body></html>");
  exit(EXIT_SUCCESS);
 }

每当执行我的HTML文件时:

输入以下内容:

用户名= 123密码= 123

这是该程序给我的输出:

 Hello Mr./Ms. 123&password=123 You entered your password (null) 

任何想法如何解决这个问题? 谢谢!

在你的代码中

char *user;
char *password;

userpassword只是未初始化的指针。

你需要这个:

char user[100];
char password[100];

但是,很可能还有其他CGI和sscanf相关的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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