Retourner au contenu. Retourner à la navigation

 

Cgi en C pour un récupérer un POST

by daharry @ 30/03/2006
Un petit morceau de code en C à utiliser comme script CGI pour récupérer la requête passée en POST et la stocker.
#include 
#include

void unencode(char *src)
{
char **tab;
int i,j;
tab = malloc((strlen(src) + 42) * sizeof(**tab));
tab[0] = malloc(sizeof(*tab[0]));
for (i = 0, j = 0;*src; src++)
if (*src == '=' || *src == '&')
{
tab[i++][j] = '\0';
tab[i] = malloc(sizeof(*tab[i]));
j = 0;
}
else
{
tab[i] = realloc(tab[i], strlen(tab[i]) + 2);
tab[i][j++] = *src;
tab[i][j+1] = '\0';
}
tab[i+1] = 0;
for (i = 0; tab[i]; i++)
printf("tab[%i] : %s\n", i, tab[i] );

}


int main(void)
{
extern char** environ;
char *lenstr;
char input[8];
long len;
printf("Content-Type:text/html\n\n");
lenstr = getenv("CONTENT_LENGTH");
sscanf(lenstr,"%ld",&len);
fgets(input, len+1, stdin);
printf("Requete entiere : %s",input);
unencode(input);
return 0;
}
Par daharry Dernière modification 22/03/2007 15:55
Navigation
Actualités
18/12/2008 Sortie d'OpenSuse 11.1
03/12/2008 Songbird 1.0
20/10/2008 Société Générale se met au vert
15/09/2008 Sortie de la version VLC 0.9.2
23/06/2008 Opération du libre à Nantes !
Plus d'actualités...
Articles
22/05/2008 Première approche de Qmail
19/05/2008 Test de la distribution Elive 1.0 Gem
14/05/2008 GNUPG introduction à la cryptographie et utilisation de GnuPG
21/02/2008 GNU / Screen
03/09/2007 The Linux File System Encryption API
More articles
Tips
28/04/2008 Mozilla Firefox : Google Talk et Facebook Chat
22/04/2008 Sed : Rechercher du texte entre deux chaines de caractères
04/04/2008 Gérer son(ses) écran(s) avec xrandr
26/03/2008 Tips sur l'historique de vos commandes
13/02/2008 Linux-Unix Cheat Sheets
More tips
Codes
09/04/2008 Chapitre 13 - Administration DNS et DHCP
09/04/2008 Chapitre 06 - Service web avec Apache
04/04/2008 Chapitre 09 - PureFTPd
04/04/2008 Chapitre 06 - Scripting Bash
01/04/2008 Chapitre 20 - Haute Disponibilité
More codes
Courses
13/09/2006 Module 3
23/02/2006 Module 2
23/02/2006 Module 1
More courses
Formation Linux

Supinfo Training Center has the first Linux Certification. The training is 13 days and allow you to pass the LPI 101 and 102.

more info
 
 
Vous êtes ici :
Codes Cgi en C pour un récupérer un POST