473,789 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manually setting session ids

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 obvious way to do this is to use the session ID. The problem is, how
to first of all generate a session ID and then send back a session ID to
reload a session.

Perhaps my understanding of sessions is too limited, but I can't see the
wood for the trees at the moment. Maybe it's obvious and I can't see it.

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

<?php
session_start() ;

function GetSessionID()
{
return session_id();
}

function SetSessionID($s ession_id)
{
session_id($ses sion_id);
}

function SetVar($var, $val)
{
$_SESSION[$var] = $val;
}

function GetVar($var)
{
return $_SESSION[$var];
}

?>

now, on the client side, the idea is to do something like this

$sid = $client->GetSessionId() ;
$client->SetSessionId($ sid);
$client->SetVar('foo' , 'bar');
echo $client->GetVar('foo' ); //returns 'bar'

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.

Even if I could change the session_id, would I get back the data I had
already set?

Does anyone have any thoughts. I'm going mad.

Sep 29 '08 #1
4 5675
*** 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_c lose();

session_id('B') ;
session_start() ;
$_SESSION['who_am_i'] = 'I am session B';
session_write_c lose();
session_id('A') ;
session_start() ;
echo $_SESSION['who_am_i'] . "\n";
session_write_c lose();

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

?>

You need to set session.use_coo kies 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
--
Sep 29 '08 #2
>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).
But for the purpose of this connection, it's another client.
>The obvious way to do this is to use the session ID. The problem is, how
to first of all generate a session ID and then send back a session ID to
reload a session.
CURL permits things such as getting the session cookie returned
from a request, saving it, and re-sending it on subsequent requests
in the same session.

The session ID is set by the server acting as a server in this situation.
It is up to the client to get the returned session ID, *NOT CHANGE IT*,
and re-use it when necessary. If you need to save the session cookie
across a PHP page in the client, use a database.

Don't confuse the session ID for server-to-server vs. the session
ID for the PHP page browser-to-server. They are two different
session IDs.
>Perhaps my understanding of sessions is too limited, but I can't see the
wood for the trees at the moment. Maybe it's obvious and I can't see it.

This is the server (pseudocode). Forget the transport mechanism, imagine
that any function can be called remotely.
That's a strange assumption.
>
<?php
session_start( );

function GetSessionID()
{
return session_id();
}

function SetSessionID($s ession_id)
{
session_id($se ssion_id);
}

function SetVar($var, $val)
{
$_SESSION[$var] = $val;
}

function GetVar($var)
{
return $_SESSION[$var];
}

?>

now, on the client side, the idea is to do something like this

$sid = $client->GetSessionId() ;
$client->SetSessionId($ sid);
$client->SetVar('foo' , 'bar');
echo $client->GetVar('foo' ); //returns 'bar'

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.

Even if I could change the session_id, would I get back the data I had
already set?

Does anyone have any thoughts. I'm going mad.

Sep 29 '08 #3
On 29 Sep, 18:33, Hugh Oxford <ares...@fas.co mwrote:
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 obvious way to do this is to use the session ID. The problem is, how
to first of all generate a session ID and then send back a session ID to
reload a session.

Perhaps my understanding of sessions is too limited, but I can't see the
wood for the trees at the moment. Maybe it's obvious and I can't see it.

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

<?php
session_start() ;

function GetSessionID()
{
return session_id();

}

function SetSessionID($s ession_id)
{
session_id($ses sion_id);

}

function SetVar($var, $val)
{
$_SESSION[$var] = $val;

}

function GetVar($var)
{
return $_SESSION[$var];

}

?>

now, on the client side, the idea is to do something like this

$sid = $client->GetSessionId() ;
$client->SetSessionId($ sid);
$client->SetVar('foo' , 'bar');
echo $client->GetVar('foo' ); //returns 'bar'

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.

Even if I could change the session_id, would I get back the data I had
already set?

Does anyone have any thoughts. I'm going mad.
You're trying to make the session model for browser wielding users fit
a server-to-server model. Start again with a blank bit of paper.

We can't advise further without knowing a lot more about the
interchange - how does security figure? Will there be multiple
clients? "Forget the transport mechanism" - do you mean we should
assume that it's transactionally secure or that this doesn't matter?
Does it have to run synchronously or asynchronously? Are you writing
the code at both ends?

C.
Sep 30 '08 #4
Hugh Oxford wrote:
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 obvious way to do this is to use the session ID. The problem is, how
to first of all generate a session ID and then send back a session ID to
reload a session.

Perhaps my understanding of sessions is too limited, but I can't see the
wood for the trees at the moment. Maybe it's obvious and I can't see it.

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

<?php
session_start() ;

function GetSessionID()
{
return session_id();
}

function SetSessionID($s ession_id)
{
session_id($ses sion_id);
}

function SetVar($var, $val)
{
$_SESSION[$var] = $val;
}

function GetVar($var)
{
return $_SESSION[$var];
}

?>

now, on the client side, the idea is to do something like this

$sid = $client->GetSessionId() ;
$client->SetSessionId($ sid);
$client->SetVar('foo' , 'bar');
echo $client->GetVar('foo' ); //returns 'bar'

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.

Even if I could change the session_id, would I get back the data I had
already set?

Does anyone have any thoughts. I'm going mad.

I don't understand what the session id has to do with what you're trying
to accomplish. In fact, I have no idea exactly what you're even trying
to accomplish.

How about describing what you're trying to do, instead of why what
you're doing won't work (and no, it won't work).

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 30 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9174
by: bagsmode | last post by:
Hi, I'm trying to set a session cookie and then redirect, however I get the error: Status: 302 Moved Location: /index.cgi I thought I recall getting an error like this when I first tried performing a redirect when I had left in print "Content-type:text/html\n\n";
4
3288
by: yohomonkey | last post by:
I want to setting the session end , but ican't waiting for the session is timeout! Who can help me?
7
1667
by: Ali | last post by:
Our security people have been able to copy and use the FormsAuthentication cookie. Our Authetication cookie is based on an encrypted ticket and we use FormsAuthentication.SignOut() when users loggout or kill their session, but apparently the secure ticket does not get removed from the server by FormsAuthetication.SignOut(). We have been able to time-out the ticket on the server, but we need to be able to remove the ticket at any time. ...
4
9330
by: fm | last post by:
We are using State Server to host our session objects. We have several applications running under IIS that will be using the State Server. How can one of those applications clear its Session state? If it was in process, we could just stop and start the web app. We can not just stop and start the State Server service because it would wipe out state for all applications.
1
3024
by: Ken Varn | last post by:
IIS has a Session Timeout setting. How does this setting coincide with the ASP.NET property Session.SessionTimeout value. If I change this value in code, will it override the IIS Session Timeout setting? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
4
9459
by: UJ | last post by:
I have a page where the user can upload a video file. As you can guess, this may take a while. Is there a way I can change the session timeout for just this one page? I would also want to change the forms authentication to be a large value for that page also. TIA - Jeff.
1
6510
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
4
7360
by: SevDer | last post by:
Hi, I've done some coding in my web application however right now for an unknown reason my asp.net 2.0 site is not setting asp.net_sessionid cookie and as a result, I am losing the session data in each page refresh or redirect. I really do not have any coding against how the session works. And I have not changed any setting in IIS. I even compared the 2 code(old and new) bases and didn't see anything funny
3
1585
by: Jankie | last post by:
Hi I have disabled cookies in my browser just to test and discovered that session cookies are still set by php.I was looking for an example to set a session id cookie manually but couldnt find it.I assume it is set automatically by php as soon as a session start directive is declared. I just want to store a session id in the cookie to remember data from page to page,not for authentication. I can set a cookie that stores a name like this ....
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.