this is my logVisit function that writes the environment variables to a file and indicates the number of hits.
Code:
/* this function logs all the visits to the server and stores info about the
client logging on, using the environment variables. Everything is stored to a file
for easy access and maintenance. to udate better and save envionemt variables use
log the time as well.
*/
#include <stdio.h>
#include "CGINCform.h"
void logVisit(void){
/* put time value in ptr to chars type as well. and the number of hits */
FILE *visits;
int var = 0;
if ( (visits = fopen("Visits.txt", "a")) == NULL){
perror("<p>Error");
return;
/*would use a return value but function returns void. not needed anyway
since the return value is used to tell the os if success or not. Possible could
use EXIT_SUCCESS OR EXIT_FAILURE but the point is it still evaluates to 0 or 1
so just like ptr2struct->member its REDUNDANT. */
}
//else
fprintf(visits,"Visit number: %d\n", Hits() );
/*actually what this means is i can create a static variable for all these vars
and put the result in a log file to find out who visits when and where. That way I
can check to see if someone is attemping to ping me interesting */
/*there are 19 environment variables defined by NCSA. Your particular server
may implement more Check your documentation */
char *Evalues[]={
/*follwing variables are not request specific */
"SERVER_SOFTWARE",/*name and version of gateway server */
"SERVER_NAME",/*server's hostname or ip addy */
"GATEWAY_INTERFACE",/*version of the CGI specification of server */
/*following varaibales are request specifie */
"SERVER_PROTOCOL",/*name and version of the server protocol */
"SERVER_PORT",/*port number to which request was sent */
"REQUEST_METHOD",/*the request method used*/
"PATH_INFO",/* */
"PATH_TRANSLATED", /* */
"SCRIPT_NAME", /*virtual path to script name */
"QUERY_STRING", /*if method was GET info up to n characters after ? character*/
"REMOTE_HOST", /*remote host making request */
"REMOTE_ADDR", /*remote address */
"AUTH_TYPE", /* if server supports authentication this is tells what protocol used */
"REMOTE_USER", /*if authuticated this is name of user */
"REMOTE_IDENT", /* if server supports RFC 931 this var returned */
"CONTENT_TYPE", /*content type of the data for query using post or put could be text/html or other */
"CONTENT_LENGTH", /*length of the content to stdin from the post method*/
"HTTP_ACCEPT", /*MIME TYPES excepted */
"HTTP_USER_AGENT", /*browser client using */
/* the following are error logs sent back by the server if anything wrong */
"REDIRECT_REQUEST", "REDIRECT_URL", "REDIRECT_STATUS",
/*not mandatory and used if going to store a cookie */
"SESSION_ID",/* for cookies. */
"HTTP_COOKIE", /*env var of cookes from the browser */
};
/*iterate through envariables and put to visits.txt.
entered in should be the environment variable and the value of the
environment variable */
while (var < 24)
fprintf(visits,"%s: %s\n", Evalues[var++], getenv(Evalues[var]) );
/* put a separator after done. Actually know could format the file as a htm. */
/*close up shop */
fputs(EndLine,visits);
fprintf(visits,"\n");/*this puts an extra line in the file so always starts on a '\n' */
if ( (fclose(visits)) !=0)
fprintf(stdout,"<h1>UNABLE TO CLOSE FILE</h1>");
else
return;
}// end of function logVisit
when i check the logvisit file it gives me this. But i believe it is because I'm accessing the site from local host.
Code:
Visit number: 6
SERVER_SOFTWARE: (null)
SERVER_NAME: (null)
GATEWAY_INTERFACE: (null)
SERVER_PROTOCOL: (null)
SERVER_PORT: (null)
REQUEST_METHOD: (null)
PATH_INFO: (null)
PATH_TRANSLATED: (null)
SCRIPT_NAME: (null)
QUERY_STRING: (null)
REMOTE_HOST: (null)
REMOTE_ADDR: (null)
AUTH_TYPE: (null)
REMOTE_USER: (null)
REMOTE_IDENT: (null)
CONTENT_TYPE: (null)
CONTENT_LENGTH: (null)
HTTP_ACCEPT: (null)
HTTP_USER_AGENT: (null)
REDIRECT_REQUEST: (null)
REDIRECT_URL: (null)
REDIRECT_STATUS: (null)
SESSION_ID: (null)
HTTP_COOKIE: (null)
===============================================
so everything is set to null. This is after i've tried to access it via my web server, not just compiling the code.
note: when i compile the code, it compiles fine - but spitting out garbege -after commenting out
Code:
//if( (strcmp(getenv("REQUEST_METHOD"),"POST"))==0){
and just assuming the HTTP method is post - which it is.
however when i run try to access the site, press submit to have my cgi data parse by my code my server crashes. and I get a internal server error 500.
I'm sorry for bringing this on you guys. As it stands now, I may need to incubate and come back, but I had code before that worked somewhat and I'd like to know why this one doesn't.