Re: Manually setting session ids



*** Hugh Oxford escribió/wrote (Mon, 29 Sep 2008 18:33:09 +0100):
I am writing some server to server software that needs to maintain state.

When I say server to server I mean that the client is not a browser, it
is another PHP server (as if that wasn't obvious).

The word "server" has lots of meanings. What do you mean exactly? If you
are connecting to a remote server using HTTP, it doesn't matter who you
are: the mechanism is exactly the same.


This is the server (pseudocode). Forget the transport mechanism, imagine
that any function can be called remotely.

You are making a rather curious assumption but...

The problem seems to be that session_start on the server side is called
at the top of the script, and there is no way to change the session_id
midstream.

.... this works for me:

<?php

session_id('A');
session_start();
$_SESSION['who_am_i'] = 'I am session A';
session_write_close();

session_id('B');
session_start();
$_SESSION['who_am_i'] = 'I am session B';
session_write_close();


session_id('A');
session_start();
echo $_SESSION['who_am_i'] . "\n";
session_write_close();

session_id('B');
session_start();
echo $_SESSION['who_am_i'] . "\n";
session_write_close();

?>

You need to set session.use_cookies to 0 in your php.ini (or use @ to hide
warnings).


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
.



Relevant Pages

  • Re: [PHP] Displaying files
    ... is running on has everything it needs to access that UNC filename. ... Stut, ... If I copy the link from the error message and paste it into a browser running from my PHP server, the file comes up just fine. ...
    (php.general)
  • Re: How to shortcut execute php script without filling out form?
    ... Or is it somehow not possible without ... If you want to retrieve data with your PHP server, then a little bit of cURL and it will all be over. ... Create an html file with this code in it: ...
    (alt.php)
  • Re: Entfernte Grafiken werden nicht angezeigt
    ... Ich haben zweimal von *meinem* Server auf den remote Server (mit den ... Und wie kommt dann Dein Browser zur Graphik? ... speichert der remote Server zuerst die ...
    (de.comp.lang.perl.misc)
  • Re: Connection problems - PHP MySQL
    ... database connection I get the "Your PHP server doesn't have the MySQL module ... downloaded the latest mysqli and mysql extensions (PHP 5.1.6 and MySQL ... I've got the same problem on IIS if you have so I can help you. ...
    (comp.lang.php)
  • Re: Connection problems - PHP MySQL
    ... create a database connection I get the "Your PHP server doesn't have the MySQL module loaded or you can't use the mysql_connect functions" error. ...
    (comp.lang.php)