#include #include #include #include #include using namespace std; main(int argc, char *argv[]) { int needacookie, newcookie, vpos ; char *envVar ; string *envVarS ; envVar = getenv("HTTP_COOKIE") ; if (envVar == (char *)NULL) needacookie = 1 ; else { envVarS = new string(envVar) ; if ((vpos=envVarS->find("visitor=")) == envVarS->npos) needacookie = 1 ; else { envVarS->erase(0, vpos+8) ; if ((vpos=envVarS->find(";")) < envVarS->npos) envVarS->erase(vpos) ; needacookie = 0 ; } } if (needacookie) { struct timeval now ; gettimeofday(&now, (struct timezone *)NULL) ; newcookie = (now.tv_sec % 1000) * 1000000 + now.tv_usec ; } cout << "Content-type: text/html" << endl ; if (needacookie) cout << "Set-Cookie: visitor=" << newcookie << "; " << "domain=cs.unca.edu; " << "path=/~brock/cgiplay/; " << "expires=Fri, 31-Dec-2012 13:46:00 GMT" << endl ; cout << endl << "" << endl << "" << endl << "Hello cookie owner" << endl << "" << endl << "" << endl << "

Hello cookie owner

" << endl ; if (needacookie) cout << "Your new cookie is " << newcookie << "" << endl ; else cout << "Your old cookie is " << *envVarS << "" << endl ; cout << "" << endl << "" << endl ; }