Programming Technology-self-made cgi programming in C language for searching

Source: Internet
Author: User
Programming Technology-compile cgi in a self-made C language to implement the search function-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1. Environment
/Usr/local/apache/htdocs/(the file to be retrieved is in this directory)
/Usr/local/apache/temp/(as a transit folder)
/Usr/local/apache/cgi-bin/
2. Place a. out generated by gcc search. c in/usr/local/apache/cgi-bin/, and set the permission to nobody.
.
3. chown-R nobody. nobody/usr/local/apache/temp
4. Add the deletetemp permission to/etc/cron. daily to 555.
Rm-f/usr/local/apache/temp /*
5. Add a file myupdate permission to/etc/cron. hourly to 555.
Updatedb-U/usr/local/apache/htdocs
6. delete a file slocate. cron in/etc/cron. daily.

Appendix (2 in total ):
1. Source Code of index.htm


Untitled Document




Enter your query string







2. Source Code of search. c
# Include
# Include
# Include
# Include
# Include

Int main (int argc, char * argv [])
{
Int fd;
Int status;
Time_t I;
Char cFileName [64];
Char cTempName [64];
Char cBuffer [1024];
Char * p = cBuffer;
Char cContent [10240];

Char * data;
Char keyword [1024];
Data = getenv ("QUERY_STRING ");
If (data = NULL)
{
Printf ("Content-Type: text/html ");
Printf ("not found! ");
Exit (1 );
}

Sscanf (data, "keyname = % s &", keyword );

P + = sprintf (p, "locate '% s' | sed-e's # ^/usr/local/apache/htdocs # http: // 129.158.217.223 # '| sed-e's # ^. * $ #&
# '> ", Keyword );
I = time (NULL );

Sprintf (cTempName, "shortd.html", I );
Sprintf (cFileName, "/usr/local/apache/temp/export d.html", I );
Strcat (cBuffer, cFileName );
CBuffer [1024-1] = 0;

System (cBuffer );
Fd = open (cFileName, O_RDWR );
Status = read (fd, cContent, sizeof (cContent)-1 );
Close (fd );

Printf ("Content-Type: text/html ");
Printf (" ", CTempName );
Printf ("Waiting .......................");
Printf ("% s", keyword );
Return 0;
}

[ Last edited by linux _ on]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.