Re: Problem with cookie based sessions

Giganews Newsgroups
Subject: Re: Problem with cookie based sessions
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Thu, 17 Sep 2009

"Christian Kaufmann" <christian.kaufma…@gmx.net> wrote in message
news:mo05b51fpkt3or876ntl52hv262iho3s…@4ax.com...

> But I cannot read the cookies in PHP

Why not?  You need to be more specific.  Did you validate that the server is
sending the cookies to your PHP script to begin with?  Did you verify that
PHP is not rejecting them?

> So I'm looking for another way. One idea is, that I send the PHP
> session id as get variable (or cookie) to my delphi application.

That is an option.  JSP does that, for instance.

> But how can I configure my TIdHttpServer component to use that
> cookie / get var as session identifier and not create a new (own) one?

TIdHTTPServer only supports cookie-based sessions natively.  For what you
are asking, you would have to set the server's AutoStartSession property to
False, and then assign the TIdHTTPRequestInfo.Session and
TIdHTTPResponseInfo.Session properties manually inside the OnCommand...
events as needed, ie:

type
  TIdHTTPRequestInfoAccess = class(TIdHTTPRequestInfo)
  end;

  TIdHTTPResponseInfoAccess = class(TIdHTTPResponseInfo)
  end;

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo:
TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  LSessionID: String;
  LSession: TIdHTTPSession;
begin
  LSessionID := ...;
  LSession := nil;

  if LSessionID <> '' then
  begin
    LSession := IdHTTPServer1.SessionList.GetSession(LSessionID,
ARequestInfo.RemoteIP);
    if LSession = nil then
    begin
      ... report an error to the client ...
      Exit;
    end;
    TIdHTTPRequestInfoAccess(ARequestInfo).FSession := LSession;
    TIdHTTPResponseInfoAccess(AResponseInfo).FSession := LSession;
  end else
  begin
    IdHTTPServer1.CreateSession(AContext, AResponseInfo, ARequestInfo);
  end;
  ...
end;

--
Remy Lebeau (Indy Team)

Replies

In response to

Problem with cookie based sessions posted by Christian Kaufmann on Thu, 17 Sep 2009