Esempio n. 1
0
        /// <summary>
        /// Starts the session if it is not started yet.
        /// </summary>
        public virtual bool StartSession(Context ctx, IHttpPhpContext webctx)
        {
            // checks and changes session state:
            if (webctx.SessionState != PhpSessionState.Closed)
            {
                return(false);
            }
            webctx.SessionState = PhpSessionState.InProgress;

            try
            {
                // ensures session and reads session data
                var session_array = this.Load(webctx) ?? PhpArray.NewEmpty();

                // sets the auto-global variable (the previous content of $_SESSION array is discarded):
                ctx.Session = session_array;
                ctx.Globals[SESSION_Variable] = session_array;

                //if (ctx.Configuration.Core.RegisterGlobals)
                //{
                //    // ctx.RegisterSessionGlobals();
                //}

                // adds/updates a SID constant:
                if (!ctx.DefineConstant(SID_Constant, GetSessionId(webctx), true))
                {
                    throw new InvalidOperationException("SID already set.");    // TODO: allow overwriting
                }
            }
            catch
            {
                webctx.SessionState = PhpSessionState.Closed;
                return(false);
            }
            finally
            {
                //
                webctx.SessionState = PhpSessionState.Started;
            }

            //
            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Constant declaration.
 /// </summary>
 public static void DeclareConstant(Context ctx, string name, ref int idx, PhpValue value)
 {
     ctx.DefineConstant(name, value, ref idx, ignorecase: false);
 }
Esempio n. 3
0
 /// <summary>
 /// Defines a constant.
 /// </summary>
 /// <param name="ctx">Current runtime context.</param>
 /// <param name="name">The name of the constant. Can be arbitrary string.</param>
 /// <param name="value">The value of the constant. Can be <B>null</B> or a scalar or array.</param>
 /// <param name="caseInsensitive">Whether the name is case insensitive.</param>
 /// <returns>Whether the new constant has been defined.</returns>
 public static bool define(Context ctx, string name, PhpValue value, bool caseInsensitive = false)
     => ctx.DefineConstant(name, value, caseInsensitive);