如何用 C 語言取得 HTML 的網址參數 (get 型)

CGI 程式設計

第一個程式

環境變數

get 參數

post 參數

常用函數

參數解碼

範例:檔案編輯

Apache 安裝

訊息

相關網站

參考文獻

最新修改

簡體版

English

程式一

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

int main(int argc, char* argv[], char *envp[])
{
   printf("Content-type: text/html\n\n");
   char *query = getenv("QUERY_STRING");
   char name[20];
   int age;
   sscanf(query, "name=%[^&]&age=%d", name, &age);
   printf("name:%s<br/>age:%d", name, age);
}

執行結果

cgiget.png

程式一的執行結果

參考文獻

  1. 利用C語言寫CGI的一些心得整理 — http://www.evanlin.com/blog/archives/000120.html

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License