|
|
|
在CGI中实现session的想法和实现
作者:Webmaster 来源:Linuxdby.com 点击:
日期:2007-04-28
[收藏] [投稿]
IE是否经常中毒?推荐您
|
void kill_session() { char *session_id; char *session_path; char sfp[128]; session_id = cgi_val(entries,"session_id"); strcpy(sfp,"/tmp"); strcat(sfp,"/sess_"); strcat(sfp,session_id); remove(sfp); } void clean_session_file() { DIR *pdir; struct dirent *ent; char *path; char *filename; char filepath[64]; int fd; char str_time[11]; time_t now; path = "/tmp"; pdir = opendir(path); if(pdir != NULL) { while( ent =readdir(pdir) ) { filename = ent->d_name; if( strncmp(filename,"sess_",5)==0 ) { strcpy(filepath,path); strcat(filepath,"/"); strcat(filepath,filename); fd = open(filepath,O_RDONLY); read(fd,str_time,10); time(&now); if( now - atoi(str_time) > atoi(parse_config_file("session_live_time")) ) { remove(filepath); } close(fd); } } } closedir(pdir); } void print_session_error(char *n) { printf("Content-type:text/html\n\n"); printf("<html><head>"; print_title("请重新登陆!"); printf("</head>\n"); printf("<body>\n"); printf("对不起,请重新登陆。<p>\n"); printf("你长时间没有操作,登陆已经超时。或者是系统发生了错误。<p>\n"); printf("如果是后者,请与管理人员联系。\n"); printf("<!--%s-->",n); printf("</body>"); printf("</html>\n"); } |
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一页 1 2 3下一页
上一篇:CGI绝对路径和相对路径的简便设置方法 下一篇:获取随机的密码
|