Bob the Builder Posted April 5, 2010 Share Posted April 5, 2010 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 More sharing options...
Bob the Builder Posted April 7, 2010 Author Share Posted April 7, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.