Hello all you great PHPers, Who among you can solve this tricky problem?
OK, a little background: my goal is to send local POST requests to some of my php pages from **within** a php program. I have already successfully done simple POST data transfers with sockets using "HTTPClient.class". This is not an issue. This class really just prints out the appropriate headers and receives a server response using sockets -- rather simple. I am now trying to get php SESSIONS to work with this socketed setup. I already have sessions working for "normal" HTTP requests. You can pass session IDs using cookies or with a POST/GET variable, as you know. Now, I've set up two files, "tst1.php" and "tst2.php". TST1 sends TST2 some POST data, and attempts to relay the session id to maintain session state: #### tst1.php #### -------------------------------------------------------------------------------------------------- include("HTTPClient.class"); session_save_path("mypathtosessions"); //No, this is not what I actually have in my code, silly session_start(); //Executes a new session. //Create socket object $HTTP = new Net_HTTP_Client("mydomain",80); //No, this is not what I actually have in my code, silly /////////////////////////////////////////////////////////////////////////////////////////////////////// // (1) GET - This example attempts to send the session ID via the GET method. If you execute the code below, // it will "lock" up. However, if you change "PHPSESSID" to, say, "blah", the code will not lock up. // There's some problem, here! $HTTP->Post("/~refcoord/tst2.php?PHPSESSID=".session_id(), // <-- array( "Bob" => "Jones", "ID_we_need_to_pass_to_tst2" => session_id() )); /////////////////////////////////////////////////////////////////////////////////////////////////////// // (2) POST - This example attempts to send the session ID via the POST method. The same set of wierd circumstances // occur here just as in GET. There's some systematic conflict occurring on the server. $HTTP->Post("/~refcoord/tst2.php", array( "Bob" => "Jones", "ID_we_need_to_pass_to_tst2" => session_id() "PHPSESSID" => session_id() // <-- )); /////////////////////////////////////////////////////////////////////////////////////////////////////// // (3) COOKIE - I even went so far as to simulate a cookie! Still, the example below locks up any server response. // again, if I change "PHPSESSID" to ANY other value, the server will at least give a response! $HTTP->addHeader("Cookie", "PHPSESSID=".session_id()); // <-- $HTTP->Post("/~refcoord/tst2.php", array( "Bob" => "Jones", "ID_we_need_to_pass_to_tst2" => session_id() )); /////////////////////////////////////////////////////////////////////////////////////////////////////// //Print out the REPSONSE we get after sending an HTTP POST request to tst2.php echo $HTTP->getBody(); /////////////////////////////////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- #### tst2.php #### -------------------------------------------------------------------------------------------------- session_save_path("mypathtosessions"); //Set the path where session files will be saved session_start(); //Starts session. If a session ID is passed to this file, // the progam will use that session. If this file does not // get passed a session id via GET/POST or COOKIE, this function // will generate a *new* ID (bad!) //Print POSTed sample data passed in from tst1.php (works 100%) echo "<br><b><u>tst2.php POSTed Data:</u></b><br>"; while (list ($name, $value) = each ($HTTP_POST_VARS)) if($name != "ID_we_need_to_pass_to_tst2") echo "$name: $value<br>\n"; //Compare the session IDs echo "<br>Session ID from tst1.php = ".$_POST["ID_we_need_to_pass_to_tst2"]; echo "<br>Session ID from tst2.php = ".session_id(); echo "<br><i>(These should be the same, but they are not! The function session_start() in<br> tst2.php has not been passed the desired SESSID and has generated its own. Bad!<br> If you hit reload, you'll see that ID1 stays the same, and ID2 regenerates itself again.)</i><br>"; -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- USING GET, POST, OR COOKIES TO PASS PHPSESSID WHEN USING THIS SOCKETED SETUP LOCKS UP SERVER RESPONSES. Currently, the only possible cause for this problem I can think of is, perhaps, the session_start() call in tst2.php sees the HTTP socket from tst1.php as coming from *OUTSIDE* the server (but it really isn't). In such cases, session_start() will not use the ID passed to it (as it should), and will generate a new session. I'm not sure if this is *the* problem, but I think I've exhausted other possibilities. Please contact me via email if you can! I really need this issue resolved. I will be happy to talk you through the problem if you're interested in solving it 8^). Thanks for reading, your help is greatly appreciated! Nicholas Singh [EMAIL PROTECTED] University of Minnesota Institute of Technology