How do you acceess $_SESSION from within CLI PHP script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    How do you acceess $_SESSION from within CLI PHP script?

    Is it possible to access values preset from $_SESSION from within a CLI
    PHP page? If so, how is it done? Each time I try to access $_SESSION
    is an empty array; the moment I leave the CLI PHP and return to my
    calling web-app PHP script, $_SESSION is back again, values and all,
    completely untouched.

    Can $_SESSION be called? If not, then I have a bigger problem inasmuch
    as $_REQUEST variables set via form/query-string MUST be accessed from
    within CLI PHP script, and the only way I can think of is to put all of
    $_REQUEST into $_SESSION, or what else do I do? Stumped.

    Thanx
    Phil

  • Oli Filth

    #2
    Re: How do you acceess $_SESSION from within CLI PHP script?

    comp.lang.php said the following on 26/04/2006 23:09:[color=blue]
    > Is it possible to access values preset from $_SESSION from within a CLI
    > PHP page? If so, how is it done? Each time I try to access $_SESSION
    > is an empty array; the moment I leave the CLI PHP and return to my
    > calling web-app PHP script, $_SESSION is back again, values and all,
    > completely untouched.
    >
    > Can $_SESSION be called? If not, then I have a bigger problem inasmuch
    > as $_REQUEST variables set via form/query-string MUST be accessed from
    > within CLI PHP script, and the only way I can think of is to put all of
    > $_REQUEST into $_SESSION, or what else do I do? Stumped.[/color]

    By definition, the CLI version of PHP is a stand-alone process. It's
    not tied in any way to a web-server, or an HTTP session, or anything
    like that. Consequently, the concept of GET/POST/session/cookie
    variables is meaningless in CLI PHP.

    Why are you calling CLI PHP from web-server-based PHP?


    --
    Oli

    Comment

    • comp.lang.php

      #3
      Re: How do you acceess $_SESSION from within CLI PHP script?


      Oli Filth wrote:[color=blue]
      > comp.lang.php said the following on 26/04/2006 23:09:[color=green]
      > > Is it possible to access values preset from $_SESSION from within a CLI
      > > PHP page? If so, how is it done? Each time I try to access $_SESSION
      > > is an empty array; the moment I leave the CLI PHP and return to my
      > > calling web-app PHP script, $_SESSION is back again, values and all,
      > > completely untouched.
      > >
      > > Can $_SESSION be called? If not, then I have a bigger problem inasmuch
      > > as $_REQUEST variables set via form/query-string MUST be accessed from
      > > within CLI PHP script, and the only way I can think of is to put all of
      > > $_REQUEST into $_SESSION, or what else do I do? Stumped.[/color]
      >
      > By definition, the CLI version of PHP is a stand-alone process. It's
      > not tied in any way to a web-server, or an HTTP session, or anything
      > like that. Consequently, the concept of GET/POST/session/cookie
      > variables is meaningless in CLI PHP.
      >
      > Why are you calling CLI PHP from web-server-based PHP?
      >[/color]

      Would you believe a requirement? Long story, but the architecture's
      that way and that way to stay. I am trying to come up with a DB based
      solution to this by stuffing serialize($_REQ UEST) into a db table, but
      I'm using $_SERVER['REMOTE_ADDR'] as the unique identifier for each
      person's filtering request, and of course, when I select from within
      the CLI PHP.. zappo! No criteria, because no $_SERVER!

      Phil
      [color=blue]
      >
      > --
      > Oli[/color]

      Comment

      • Gordon Burditt

        #4
        Re: How do you acceess $_SESSION from within CLI PHP script?

        >Is it possible to access values preset from $_SESSION from within a CLI[color=blue]
        >PHP page?[/color]

        There are no sessions for command-line PHP. There aren't any "pages",
        either, just command scripts. Also no $_GET, $_POST, $_REQUEST, or $_COOKIE.
        But there are command-line arguments.
        [color=blue]
        >If so, how is it done? Each time I try to access $_SESSION
        >is an empty array; the moment I leave the CLI PHP and return to my
        >calling web-app PHP script, $_SESSION is back again, values and all,
        >completely untouched.[/color]
        [color=blue]
        >Can $_SESSION be called?[/color]

        How does one "call" something that's not code? You could pass command-line
        arguments. Those are strings, not arrays.
        [color=blue]
        >If not, then I have a bigger problem inasmuch
        >as $_REQUEST variables set via form/query-string MUST be accessed from
        >within CLI PHP script, and the only way I can think of is to put all of
        >$_REQUEST into $_SESSION, or what else do I do? Stumped.[/color]

        Why are you using CLI PHP invoked from a form? It seems like a classic
        case of trying to drive in nails with a squirrel because you had a squirrel
        handy. Use the right tool for the job, which I suspect may involve
        include, require, and/or eval and no separate CLI anything.

        Gordon L. Burditt

        Comment

        • Gordon Burditt

          #5
          Re: How do you acceess $_SESSION from within CLI PHP script?

          >> > Is it possible to access values preset from $_SESSION from within a CLI[color=blue][color=green][color=darkred]
          >> > PHP page? If so, how is it done? Each time I try to access $_SESSION
          >> > is an empty array; the moment I leave the CLI PHP and return to my
          >> > calling web-app PHP script, $_SESSION is back again, values and all,
          >> > completely untouched.
          >> >
          >> > Can $_SESSION be called? If not, then I have a bigger problem inasmuch
          >> > as $_REQUEST variables set via form/query-string MUST be accessed from
          >> > within CLI PHP script, and the only way I can think of is to put all of
          >> > $_REQUEST into $_SESSION, or what else do I do? Stumped.[/color]
          >>
          >> By definition, the CLI version of PHP is a stand-alone process. It's
          >> not tied in any way to a web-server, or an HTTP session, or anything
          >> like that. Consequently, the concept of GET/POST/session/cookie
          >> variables is meaningless in CLI PHP.
          >>
          >> Why are you calling CLI PHP from web-server-based PHP?
          >>[/color]
          >
          >Would you believe a requirement? Long story, but the architecture's
          >that way and that way to stay. I am trying to come up with a DB based
          >solution to this by stuffing serialize($_REQ UEST) into a db table, but
          >I'm using $_SERVER['REMOTE_ADDR'] as the unique identifier for each
          >person's filtering request, and of course, when I select from within
          >the CLI PHP.. zappo! No criteria, because no $_SERVER![/color]

          So pass the correct answer to the CLI PHP, and have it return it.
          That keeps the architecture but still gets the job done.

          You *CAN* pass command-line arguments (strings), which could include
          passing your unique identifier in.

          Gordon L. Burditt

          Comment

          • comp.lang.php

            #6
            Re: How do you acceess $_SESSION from within CLI PHP script?


            Gordon Burditt wrote:[color=blue][color=green][color=darkred]
            > >> > Is it possible to access values preset from $_SESSION from within a CLI
            > >> > PHP page? If so, how is it done? Each time I try to access $_SESSION
            > >> > is an empty array; the moment I leave the CLI PHP and return to my
            > >> > calling web-app PHP script, $_SESSION is back again, values and all,
            > >> > completely untouched.
            > >> >
            > >> > Can $_SESSION be called? If not, then I have a bigger problem inasmuch
            > >> > as $_REQUEST variables set via form/query-string MUST be accessed from
            > >> > within CLI PHP script, and the only way I can think of is to put all of
            > >> > $_REQUEST into $_SESSION, or what else do I do? Stumped.
            > >>
            > >> By definition, the CLI version of PHP is a stand-alone process. It's
            > >> not tied in any way to a web-server, or an HTTP session, or anything
            > >> like that. Consequently, the concept of GET/POST/session/cookie
            > >> variables is meaningless in CLI PHP.
            > >>
            > >> Why are you calling CLI PHP from web-server-based PHP?
            > >>[/color]
            > >
            > >Would you believe a requirement? Long story, but the architecture's
            > >that way and that way to stay. I am trying to come up with a DB based
            > >solution to this by stuffing serialize($_REQ UEST) into a db table, but
            > >I'm using $_SERVER['REMOTE_ADDR'] as the unique identifier for each
            > >person's filtering request, and of course, when I select from within
            > >the CLI PHP.. zappo! No criteria, because no $_SERVER![/color]
            >
            > So pass the correct answer to the CLI PHP, and have it return it.
            > That keeps the architecture but still gets the job done.
            >
            > You *CAN* pass command-line arguments (strings), which could include
            > passing your unique identifier in.
            >[/color]

            What I wound up doing was to stuff the entire contents of $_REQUEST as
            a serialized string into a database table and retrieving it that way
            from within the CLI PHP. Thanx!
            Phil
            [color=blue]
            > Gordon L. Burditt[/color]

            Comment

            Working...