fsockopen and session_start

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



*This message was transferred with a trial version of CommuniGate(tm) Pro*

Hi,

I am using fsockopen to simulate a POST to another page (test_post.php) within 
the same server.

Data sent to the socket is:
  "POST $uri HTTP/1.1\r\n".
  "Host: $host\n". "User-Agent: mandapost\r\n".
  "Cookie: ".session_name()."=". session_id()."\r\n".
  "Content-Type: application/x-www-form-urlencoded\r\n".
  "Content-Length: $contentlength\r\n".
  "Connection: close\r\n\r\n".
  "$my_post_variables\r\n";

$_SESSION is used to hold some variables.

test_post.php is:
<?php
session_start();
echo "User".$_SESSION["user"];
...


The problem is that session_start creates a new session instead of using the 
session_id indicated in the cookie.

A user comment in the online PHP manual says:
"Just for info, session_start() blocks if another PHP using the same session 
is still running in background. It seems it's waiting the other PHP to 
finish... and sometimes it can be a problem. Create 2 different sessions by 
setting 2 different names : session_name() solve the problem."

The above comment seems correct and PHP hangs until some time-out or something 
occurs. The previous session is not started anyway.
I tried to change the name with use session_name, to change the ID with 
session_regenerate_id, also some tests with session_id, ...
I also tried to send data to the sockect using PHPSESSID and $_COOKIE instead 
of session_name and session_id.

This is my current code:
<?php
$previous_name = session_name("MASIVO");
//sessionid($previous_name);

session_start();
//session_regenerate_id();

echo "##".$previous_name."##".$_COOKIE[$previous_name]."##"; // (1)
echo "User".$_SESSION["user"];

(1) It is correct: ##PHPSESSID##09a169b69eccbf2dd49407c5d4cc84aa##

And this is what the socket returns:
HTTP/1.1 200 OK Date: Mon, 07 Mar 2005 13:43:51 GMT Server: Apache/1.3.28 
(Unix) PHP/4.3.3 mod_ssl/2.8.15 OpenSSL/0.9.7c X-Powered-By: PHP/4.3.3 
Set-Cookie: MASIVO=79241c1fb5309b6487f689eb30c65caa; path=/ Expires: Thu, 19 
Nov 1981 08:52:00 GMT Cache-Control: private, max-age=10800, pre-check=10800 
Last-Modified: Mon, 7 Mar 2005 13:38:57 GMT Connection: close 
Transfer-Encoding: chunked Content-Type: text/html c7 
##PHPSESSID##09a169b69eccbf2dd49407c5d4cc84aa##
Notice: Undefined index: user in ... etzetera

I am running out of ideas. Could anyboy help ?

Thanks,

Pedro.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux