Thread: Can C++ be used to create server scripts like php or cgi?

  1. #1
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499

    Can C++ be used to create server scripts like php or cgi?

    I want to know if I can use C++ to allow for dynamic webpage creation, and stuff like that, similar to cgi and php scripts. I don't want to have to learn a new languge, if possible. And I do need to create interactive pages.

    Thanks in advance

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    I believe it is possible to write CGI with C++. I dont really know much about though.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    of course. but what you're talking about is basically writing a preprocesser like PHP that understands HTML, right? seems like learning a new language would be a lot easier - not to mention most servers out there aren't going to run just any executable on their machines...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    169
    you could, but if your going for easy then learning php or cgi would be the easier way

  5. #5
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    If it is possible to write cgi scripts using C++, I would do that. I'm just wondering, is cgi compiled? Otherwise, since my site is not self-hosted, it would not be certain that the server would run the compiled code.

  6. #6
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    cgi is not a language, it's a protocol.
    Your php or Perl interpreter is a cgi program.
    cgi programs (strictly speaking libraries of course as they run inside something else) can be created using pretty much anything.
    C is the most commonly used language, but C++, Delphi, Python, and others, can also be used.

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    http://www.boutell.com/cgic/

    Library for making CGI scripts in C, which might be used in C++ (Haven't tried)

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    if you're going to be using CGI anyway, I'd suggest learning PERL instead of trying to do it with C/C++ - You'll find that you don't want a compiled binary for every little errand you want done quickly
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    But computers are so fast anyway, (I'm using a iMac G5) would compiling really be a problem?

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ...you don't seem to get it...

    First, you can't create a "script" with a compiled language, so the real answer to your original question is: no.

    Second, I mean what if you want to open a file, remove timestamps, and then close the file. IMO, it's faster to write the code, then type "perl killstamps.pl" then write the code, wait for it to compile, then run it. It also makes things cleaner, because now you just have a script lying around. With C/C++, you have both the source and a compiled binary. Get rid of the source and you can't rebuild the binary. Get rid of the binary and you have to recompile the source.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by jwenting
    cgi is not a language, it's a protocol.
    Your php or Perl interpreter is a cgi program.
    They aren't CGI programs, they're just interpreters for PHP and Perl. Well, PHP is usually used as an Apache module.

    CGI programs don't run inside anything else; they're just processes with stdin and stdout piped to certain places, with some environment variables set up certain ways.

    This is a pretty good tutorial that explains low-level what's going on: http://www.cs.tut.fi/~jkorpela/forms/cgic.html
    Last edited by Rashakil Fol; 03-16-2006 at 09:28 PM.
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Server and Client process
    By wise_ron in forum Networking/Device Communication
    Replies: 1
    Last Post: 10-07-2006, 01:11 AM
  2. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM
  3. Create an FTP Server
    By Epo in forum Networking/Device Communication
    Replies: 11
    Last Post: 01-22-2004, 09:17 PM
  4. Visual Studio and FTP Server...
    By Grayson_Peddie in forum Networking/Device Communication
    Replies: 0
    Last Post: 09-03-2003, 12:31 PM
  5. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 04:09 PM