简体   繁体   English

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

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

I started experimenting with C/CGI/HTML a few days ago. 几天前,我开始尝试使用C / CGI / HTML。 I was piqued by some log-in page program that I saw so I tried to do my own: 我被看到的某些登录页面程序激怒了,所以我尝试自己做:

Here's my program: 这是我的程序:

#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);
 }

And whenever I execute my HTML file: 每当执行我的HTML文件时:

with an input of: 输入以下内容:

username = 123 password = 123 用户名= 123密码= 123

This is the output that this program gives me: 这是该程序给我的输出:

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

Any idea how to fix this? 任何想法如何解决这个问题? Thanks! 谢谢!

In your piece of code 在你的代码中

char *user;
char *password;

user and password are just uninitialized pointers. userpassword只是未初始化的指针。

You need this: 你需要这个:

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

But there are most likely other CGI and sscanf related problems. 但是,很可能还有其他CGI和sscanf相关的问题。

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

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