Jump to content

Recommended Posts

Hello,

 

I recently started writing my own web server in Java. I have PHP working, but I can't figure out how to pass cookies to the CGI.

 

Here's a quick snippet of the general code that I'm using (and then reading the output and writing it to the browser):

Runtime.getRuntime().exec("php-cgi C:\test.php test=1 test2=2");

 

That works fine for arguments, but I can't seem to find a way to pass cookies that were read from the HTTP request header. Does anyone know if it's possible, and if so how?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/197615-php-cgi-cookies/
Share on other sites

I've figured it out; I can pass them to the CGI process using environmental variables.

 

                ArrayList<String> envp = new ArrayList<String>();
                for (Map.Entry<String, String> entry : System.getenv().entrySet()) { // Add the computer set variables.
                    envp.add(entry.getKey() + "=" + entry.getValue());
                }
                envp.add("HTTP_KEEP_ALIVE=" + httpRequest.getHeaderProperty("Keep-Alive"));
                envp.add("HTTP_CONNECTION=" + httpRequest.getHeaderProperty("Connection"));
                envp.add("HTTP_COOKIE=" + httpRequest.getHeaderProperty("Cookie"));
                envp.add("HTTP_CACHE_CONTROL=" + httpRequest.getHeaderProperty("Cache-Control"));
                Process process = Runtime.getRuntime().exec(command, envp.toArray(new String[envp.size()])); // Execute php-cgi.exe

 

Which works great. That said, I have a new problem: passing POST. I've tried multiple different names, such as POST, HTTP_POST, HTTP_POST_VARS, etc, but none add to $_POST. Does anyone know what environmental variable PHP uses for POST?

Link to comment
https://forums.phpfreaks.com/topic/197615-php-cgi-cookies/#findComment-1038136
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.