Thread: Enabling PHP support for my C http server.

  1. #1
    Registered User
    Join Date
    Feb 2021
    Posts
    2

    Red face Enabling PHP support for my C http server.

    Hi everybody! I'm writing a HTTP server from scratch in C on Linux, using the C Standard Library. I managed to enable it to send/receive http requests and show html/css/js pages on a web browser, when a client requests them.

    But now, I'm trying to make it able to work with PHP. I'm relatively new to all this networking stuff, so please explain any terminology in your explanations.

    Back when I was using Apache http server, it already knew how to work with PHP - I had an AJAX jQuery script that creates browser variables from user input (like entering their name and password on a registration page), and then this script sends these variables to a PHP file, which worked fine.

    However, now that I'm writing my own HTTP server in C, I'm wondering how to enable this server to work with PHP too? Is there a C standard header that enables that? How would adding PHP support for my C http server work in general, and more specifically?

    You can see my server C code on the attachment,

    Thank you all so much in advance!
    Attached Files Attached Files

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Unless you want to work out how to integrate PHP into your web server, say with some kind of module system like what many web servers around do, I think your best bet would be to look at using PHP as a CGI program. So you implement whatever is required of the web server according to the CGI specification, then the HTTP request becomes input to the PHP script that is executed with the PHP CGI binary, and your web server will serve its output to the web browser.

    The PHP docs warn about potential vulnerabilities with using PHP as a CGI program though: Security of PHP when Installed as CGI binary
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2021
    Posts
    2
    Thanks for the info, I have already figured out that it has something to do with CGI (Common Gate Interface), but what this abbreviation stands for is pretty much all I know about it.

    Do you know of any good tutorials for beginners in networking that explain what CGI is and how exactly it works? I'm still pretty lost and the documentations/code they show on manuals is too technical for my very limited networking knowledge. >_<

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Http cgi server
    By kapil1089thekin in forum C Programming
    Replies: 15
    Last Post: 02-04-2011, 09:07 AM
  2. http server
    By kapil1089thekin in forum C Programming
    Replies: 14
    Last Post: 01-18-2011, 02:39 PM
  3. looking for small freeware library that support http connections
    By umen242 in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-23-2008, 03:21 AM
  4. HTTP Server
    By madmardigan53 in forum Networking/Device Communication
    Replies: 3
    Last Post: 09-03-2004, 01:39 PM
  5. Good free server with PHP support?
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 12-13-2002, 08:48 PM

Tags for this Thread