2

I'm working on a Website made with the proprietary DBMS "4th Dimension". I'm really struggling with this, as I'm still a beginner, and I only have experience with PHP on client-server apps. 4D provides a Web Server that can handle GET and POST requests, and send basic responses to the client.

My question is: There seems to be no equivalent of PHP's $_SESSION to store persistant variables, but I have to keep a browsing history during the visitor's session, what's the good way to achieve that?

I don't even have a clue on how I could identify a single visitor during his visit. I would really appreciate some help. Regards, caffein

TL;DR What's the best way to mimic PHP's session in any language?

Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
monsieur_h
  • 1,360
  • 1
  • 10
  • 20

2 Answers2

2

Check out this Summit session from the 4D knowledge base: Web Session Management: Tracking Your Web Users. It is complete with notes and a sample .4DB.

I'd also recommend a more thorough search on the KB and the iNUG mailing list (you have to be manually approved before you can post, but you can browse archives).

As much as I like SO the iNUG really is the best place to get in touch with 4D devs.

Joshua Hunter
  • 515
  • 4
  • 8
  • Thank you for your accurate answer. 4D hasn't a very open community, and it's hard to find answers; this question was kind of a bottle in the sea. By the way, I find unthinkable for a modern language not to propose a native way to manage sessions. – monsieur_h Jul 18 '11 at 06:58
0

The 4d v14 has native session management; to active it it is enough to set on the "Automatic Session Management" option in Database Settings ( cfr 4d Web Session Management ) or use the command WEB SET OPTION(Web Keep session; true).

The session is maintained from 4d using cookies; every process variable and records selection is maintained.

In the code of "On Web Connection" Database method you can write:

C_TEXT(www_SessionID)
If(www_SessionID=**WEB Get Current Session ID**)
    // All variables and selection already exist
    ...
Else
    // Compiler_Web has just been executed.
    // This is a new session, no variable or selection exists
    // Keep track of the session that 4D just created
    www_SessionID:=**WEB Get Current Session ID**

    // Initialization of session
    // Set up selections
    // find connected user
    QUERY([User];[User]Login=www_Login)
    QUERY([prefs];[prefs]Login=www_Login)

    // Setup variables
    // Get prefs for this user
    www_UserName:=[User]Name
    www_UserMail:=[User]mail
End if
Umberto Migliore
  • 317
  • 4
  • 17