Reading a cookie

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerim79

    Reading a cookie

    I did try to find the answer to this before posting, so this isn't a
    knee jerk reaction.

    What I am trying to accomplish is to have a script that opens a
    cookie, reads a value, and then use a switch/case to take action based
    on that value in the cookie. I want to set the cookie manually, so I
    don't need setcookie(). I see that in PHP it stores the cookie in
    memory. Is there a way to have PHP just read a cookie from the desktop
    machine? Does it have to set it first? Am I better off with Javascript
    for this?

    The situation is that we have 4 computers. We also have 4 different
    types of specialty printers, each for a different function. We don't
    know which computer will be hooked up to which printer, and they may
    be switched out routinely. We are trying to develop a simple script
    that reads the value of the cookie which tells it which printer to
    print to and what to print. This way, we can easily switch computers
    around as needed, and will only need to change the value in the cookie
    to have it access the correct code so that it prints the correct
    information in the correct format.

  • P Pulkkinen

    #2
    Re: Reading a cookie


    "Jerim79" <mylek@hotmail. comkirjoitti
    viestissä:11707 73276.017695.16 2470@v45g2000cw v.googlegroups. com...
    What I am trying to accomplish is to have a script that opens a
    cookie, reads a value, and then use a switch/case to take action based
    on that value in the cookie. I want to set the cookie manually, so I
    don't need setcookie(). I see that in PHP it stores the cookie in
    memory. Is there a way to have PHP just read a cookie from the desktop
    machine? Does it have to set it first? Am I better off with Javascript
    for this?
    I hope i don't miss some point, but generally speaking:

    1) On page #1 EITHER php during the page rendering OR client javascript
    anytime, even later, SETS UP a cookie.
    2) Person clicks a link submits a form to MOVE ON to page #2 on same domain.
    3) On page #2 EITHER php OR client javascript READS that cookie and have
    some fun with it (does it's thing).

    Of course even both can set cookies and have fun together, but that' not the
    point.

    No comments on the final problem, but somehow i felt that this needed to be
    written to clarify.


    Comment

    • P Pulkkinen

      #3
      Re: Reading a cookie

      I hope i don't miss some point, but generally speaking:
      >
      1) On page #1 EITHER php during the page rendering OR client javascript
      anytime, even later, SETS UP a cookie.
      2) Person clicks a link submits a form to MOVE ON to page #2 on same
      domain.
      3) On page #2 EITHER php OR client javascript READS that cookie and have
      some fun with it (does it's thing).
      But of course it needs to be added that ajax, i believe, gives more
      opportunities to play with cookies, since php calls are not restricted to
      initial page rendering.


      Comment

      • Jerim79

        #4
        Re: Reading a cookie

        On Feb 6, 9:03 am, "P Pulkkinen"
        <perttu.POISTAT AMA.pulkki...@P OISTATAMA.elisa net.fiwrote:
        "Jerim79" <m...@hotmail.c omkirjoitti
        viestissä:11707 73276.017695.16 2...@v45g2000cw v.googlegroups. com...
        >
        What I am trying to accomplish is to have a script that opens a
        cookie, reads a value, and then use a switch/case to take action based
        on that value in the cookie. I want to set the cookie manually, so I
        don't need setcookie(). I see that in PHP it stores the cookie in
        memory. Is there a way to have PHP just read a cookie from the desktop
        machine? Does it have to set it first? Am I better off with Javascript
        for this?
        >
        I hope i don't miss some point, but generally speaking:
        >
        1) On page #1 EITHER php during the page rendering OR client javascript
        anytime, even later, SETS UP a cookie.
        2) Person clicks a link submits a form to MOVE ON to page #2 on same domain.
        3) On page #2 EITHER php OR client javascript READS that cookie and have
        some fun with it (does it's thing).
        >
        Of course even both can set cookies and have fun together, but that' not the
        point.
        >
        No comments on the final problem, but somehow i felt that this needed to be
        written to clarify.
        Not exactly.We will have a simple registration form that a customer
        fills out at a kiosk. They click submit and the customer is done. From
        there the registration info is sent to a PHP script which first opens
        a cookie on the client computer and reads the value. Next, it runs
        through a list of switch/case statements based on that value to
        determine which printer the client computer is using and what format
        it needs to print in (This is for remote printing, to one of four
        possible printers). This way, when we move a computer to a different
        printer, we just change the value in the cookie and it starts printing
        correctly. (We are using a remote server for the data collection, and
        local PC to print.)

        Since each printer is different, the setcookie() method would not
        work because it can only set one value across four machines (Unless we
        did four different scripts, which would get confusing). We need to be
        able to have four different values for the same cookie. We also need
        to be able to manually change the value when the computer moves. Think
        of a file that you create on four different computers. Each file has
        the same name, but a different letter in it; A, B, C or D. The program
        opens the file up on each computer, reads in A, B, C or D. Then it
        takes action on whether the file contained A, B, C or D. That is what
        we are trying to accomplish with cookies. We don't want to create the
        file each time the program runs, because the file is already there.

        Comment

        • P Pulkkinen

          #5
          Re: Reading a cookie

          So - if I understand right- situation is this:

          - There are four printers.
          - Those machines that are somewhere close to printer x, should be able to
          communicate to php (when it's rendering the page) that all php-made-printing
          from this page request goes to printer x, since it is server PHP that
          prints, not the local machine.
          - Your personnel - but nobody else - can move any computer to a new
          location, that is, closer to another printer than before.
          - That's why you need to be able to change easily that location info, that
          is again permanent, until you decide move the computer again.

          Question is then also, is the cookie right or only way to accomplish this?

          Usually kiosks use kiosk mode of the browser. You can start the browser
          with http://example.com?printer=a or http://example.com?printer=b etc.,
          after that it would be php session variable that can hold the info on the
          printer. Or cookie. You could have four shortcut icons on the desktop to
          make the starting easy. You could name them in descriptive way:
          START-HERE-WHEN-UR-CLOSE-2-PRINTER-X

          May it be my stupidity, if I misunderstood you. I hope you find the solution
          anyway.


          Comment

          • Jerry Stuckle

            #6
            Re: Reading a cookie

            Jerim79 wrote:
            I did try to find the answer to this before posting, so this isn't a
            knee jerk reaction.
            >
            What I am trying to accomplish is to have a script that opens a
            cookie, reads a value, and then use a switch/case to take action based
            on that value in the cookie. I want to set the cookie manually, so I
            don't need setcookie(). I see that in PHP it stores the cookie in
            memory. Is there a way to have PHP just read a cookie from the desktop
            machine? Does it have to set it first? Am I better off with Javascript
            for this?
            >
            The situation is that we have 4 computers. We also have 4 different
            types of specialty printers, each for a different function. We don't
            know which computer will be hooked up to which printer, and they may
            be switched out routinely. We are trying to develop a simple script
            that reads the value of the cookie which tells it which printer to
            print to and what to print. This way, we can easily switch computers
            around as needed, and will only need to change the value in the cookie
            to have it access the correct code so that it prints the correct
            information in the correct format.
            >
            You can use a cookie for this. But here's a suggestion - have a
            password-protected admin page which sets the cookie. When they move the
            computer, they have to log into the admin page and tell it which printer
            to use.

            This then sets the cookie, which is now available for the rest of your
            pages. Of course, you would want to ensure that cookies are not cleared
            when the browser shuts down - at least not for your site.

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

            Comment

            • Jerim79

              #7
              Re: Reading a cookie

              On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              Jerim79 wrote:
              I did try to find the answer to this before posting, so this isn't a
              knee jerk reaction.
              >
              What I am trying to accomplish is to have a script that opens a
              cookie, reads a value, and then use a switch/case to take action based
              on that value in thecookie. I want to set thecookiemanual ly, so I
              don't need setcookie(). I see that in PHP it stores thecookiein
              memory. Is there a way to have PHP just read acookiefrom the desktop
              machine? Does it have to set it first? Am I better off with Javascript
              for this?
              >
              The situation is that we have 4 computers. We also have 4 different
              types of specialty printers, each for a different function. We don't
              know which computer will be hooked up to which printer, and they may
              be switched out routinely. We are trying to develop a simple script
              that reads the value of thecookiewhich tells it which printer to
              print to and what to print. This way, we can easily switch computers
              around as needed, and will only need to change the value in thecookie
              to have it access the correct code so that it prints the correct
              information in the correct format.
              >
              You can use acookiefor this. But here's a suggestion - have a
              password-protected admin page which sets thecookie. When they move the
              computer, they have to log into the admin page and tell it which printer
              to use.
              >
              This then sets thecookie, which is now available for the rest of your
              pages. Of course, you would want to ensure that cookies are not cleared
              when the browser shuts down - at least not for your site.
              >
              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstuck...@attgl obal.net
              =============== ===
              I talked with my boss, and he is completely against the kiosk mode
              (for whatever reason). Let's step back from the word cookie for a
              minute.

              We are going to have 4 "kiosk" style computers, each of which display
              the same registration form on a remote server. As the customer fills
              out the form, he may get redirected to other forms based on how he
              answered (Multiple paths). The very last step for everyone, after
              everything is filled out and the customer submits the form, we want to
              have a small script on the server that accesses a file on the kiosk
              computer. The script on the server will read the value and perform an
              action based on that value.

              Cookie is the word my boss threw out there. I don't see why it has to
              be a cookie, if PHP can access a remote file on the "kiosk" machine
              from the server. We don't want to pass the value with the URL, as he
              would have to go back and change all the pages of the PHP form to
              pickup the value and pass it along to the next page.

              Comment

              • Jerry Stuckle

                #8
                Re: Reading a cookie

                Jerim79 wrote:
                On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                >Jerim79 wrote:
                >>I did try to find the answer to this before posting, so this isn't a
                >>knee jerk reaction.
                >>What I am trying to accomplish is to have a script that opens a
                >>cookie, reads a value, and then use a switch/case to take action based
                >>on that value in thecookie. I want to set thecookiemanual ly, so I
                >>don't need setcookie(). I see that in PHP it stores thecookiein
                >>memory. Is there a way to have PHP just read acookiefrom the desktop
                >>machine? Does it have to set it first? Am I better off with Javascript
                >>for this?
                >>The situation is that we have 4 computers. We also have 4 different
                >>types of specialty printers, each for a different function. We don't
                >>know which computer will be hooked up to which printer, and they may
                >>be switched out routinely. We are trying to develop a simple script
                >>that reads the value of thecookiewhich tells it which printer to
                >>print to and what to print. This way, we can easily switch computers
                >>around as needed, and will only need to change the value in thecookie
                >>to have it access the correct code so that it prints the correct
                >>information in the correct format.
                >You can use acookiefor this. But here's a suggestion - have a
                >password-protected admin page which sets thecookie. When they move the
                >computer, they have to log into the admin page and tell it which printer
                >to use.
                >>
                >This then sets thecookie, which is now available for the rest of your
                >pages. Of course, you would want to ensure that cookies are not cleared
                >when the browser shuts down - at least not for your site.
                >>
                >--
                >============== ====
                >Remove the "x" from my email address
                >Jerry Stuckle
                >JDS Computer Training Corp.
                >jstuck...@attg lobal.net
                >============== ====
                >
                I talked with my boss, and he is completely against the kiosk mode
                (for whatever reason). Let's step back from the word cookie for a
                minute.
                >
                We are going to have 4 "kiosk" style computers, each of which display
                the same registration form on a remote server. As the customer fills
                out the form, he may get redirected to other forms based on how he
                answered (Multiple paths). The very last step for everyone, after
                everything is filled out and the customer submits the form, we want to
                have a small script on the server that accesses a file on the kiosk
                computer. The script on the server will read the value and perform an
                action based on that value.
                >
                A problem here. The server cannot read a file on the client system.
                This would be a huge security risk if it could be done.
                Cookie is the word my boss threw out there. I don't see why it has to
                be a cookie, if PHP can access a remote file on the "kiosk" machine
                from the server. We don't want to pass the value with the URL, as he
                would have to go back and change all the pages of the PHP form to
                pickup the value and pass it along to the next page.
                >
                It about has to be a cookie because security prevents anything on the
                server from reading anything on the client not sent directly by the
                browser. And javascript cannot access files on the client computer, either.

                Can you imagine what fun the hackers would have if there were a way to
                read files on your computer when you visit a website?

                So you're pretty much stuck with a cookie if you want something specific
                to that machine.

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

                Comment

                • Jerim79

                  #9
                  Re: Reading a cookie

                  On Feb 7, 10:17 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                  Jerim79 wrote:
                  On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                  Jerim79 wrote:
                  >I did try to find the answer to this before posting, so this isn't a
                  >knee jerk reaction.
                  >What I am trying to accomplish is to have a script that opens a
                  >>cookie, reads a value, and then use a switch/case to take action based
                  >on that value in thecookie. I want to set thecookiemanual ly, so I
                  >don't need setcookie(). I see that in PHP it stores thecookiein
                  >memory. Is there a way to have PHP just read acookiefrom the desktop
                  >machine? Does it have to set it first? Am I better off with Javascript
                  >for this?
                  >The situation is that we have 4 computers. We also have 4 different
                  >types of specialty printers, each for a different function. We don't
                  >know which computer will be hooked up to which printer, and they may
                  >be switched out routinely. We are trying to develop a simple script
                  >that reads the value of thecookiewhich tells it which printer to
                  >print to and what to print. This way, we can easily switch computers
                  >around as needed, and will only need to change the value in thecookie
                  >to have it access the correct code so that it prints the correct
                  >information in the correct format.
                  You can use acookiefor this. But here's a suggestion - have a
                  password-protected admin page which sets thecookie. When they move the
                  computer, they have to log into the admin page and tell it which printer
                  to use.
                  >
                  This then sets thecookie, which is now available for the rest of your
                  pages. Of course, you would want to ensure that cookies are not cleared
                  when the browser shuts down - at least not for your site.
                  >
                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstuck...@attgl obal.net
                  =============== ===
                  >
                  I talked with my boss, and he is completely against the kiosk mode
                  (for whatever reason). Let's step back from the wordcookiefor a
                  minute.
                  >
                  We are going to have 4 "kiosk" style computers, each of which display
                  the same registration form on a remote server. As the customer fills
                  out the form, he may get redirected to other forms based on how he
                  answered (Multiple paths). The very last step for everyone, after
                  everything is filled out and the customer submits the form, we want to
                  have a small script on the server that accesses a file on the kiosk
                  computer. The script on the server will read the value and perform an
                  action based on that value.
                  >
                  A problem here. The server cannot read a file on the client system.
                  This would be a huge security risk if it could be done.
                  >
                  Cookieis the word my boss threw out there. I don't see why it has to
                  be acookie, if PHP can access a remote file on the "kiosk" machine
                  from the server. We don't want to pass the value with the URL, as he
                  would have to go back and change all the pages of the PHP form to
                  pickup the value and pass it along to the next page.
                  >
                  It about has to be acookiebecause security prevents anything on the
                  server from reading anything on the client not sent directly by the
                  browser. And javascript cannot access files on the client computer, either.
                  >
                  Can you imagine what fun the hackers would have if there were a way to
                  read files on your computer when you visit a website?
                  >
                  So you're pretty much stuck with acookieif you want something specific
                  to that machine.
                  >
                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstuck...@attgl obal.net
                  =============== ===
                  Okay, so we are going with cookies. The problem I have is that I don't
                  know how to make PHP just read a cookie. I understand how to set a
                  cookie, and it is stored in memory, which then can be used throughout
                  the form. I even know how to set a time limit on a cookie to make it
                  stay on the kiosk computer, but again, we don't want to create the
                  cookie.

                  The problem is that I don't want to set a cookie. I want to just read
                  one that I create manually. Obviously, setting a cookie through our
                  PHP form would only be able to set one value for all four machines,
                  yet we want to have 4 different values. Is there a way to just read a
                  cookie without setting it through PHP?

                  Comment

                  • Rik

                    #10
                    Re: Reading a cookie

                    Jerim79 <mylek@hotmail. comwrote:
                    Okay, so we are going with cookies. The problem I have is that I don't
                    know how to make PHP just read a cookie.
                    It's in the $_COOKIE array.
                    --
                    Rik Wasmus

                    Comment

                    • Jerim79

                      #11
                      Re: Reading a cookie

                      On Feb 7, 10:46 am, Rik <luiheidsgoe... @hotmail.comwro te:
                      Jerim79 <m...@hotmail.c omwrote:
                      Okay, so we are going with cookies. The problem I have is that I don't
                      know how to make PHP just read acookie.
                      >
                      It's in the $_COOKIE array.
                      --
                      Rik Wasmus
                      I tried that and it doesn't seem to work. For instance:

                      <?php

                      switch ($_COOKIE["printer"]) {

                      case A:
                      echo "Hello";
                      break;
                      case B:
                      echo "Yes";
                      break;
                      case C:
                      echo "No";
                      break;
                      case D:
                      echo "Goodbye";
                      break;
                      }
                      ?>


                      That doesn't do anything.

                      Comment

                      • Rik

                        #12
                        Re: Reading a cookie

                        Jerim79 <mylek@hotmail. comwrote:
                        On Feb 7, 10:46 am, Rik <luiheidsgoe... @hotmail.comwro te:
                        >Jerim79 <m...@hotmail.c omwrote:
                        Okay, so we are going with cookies. The problem I have is that I don't
                        know how to make PHP just read acookie.
                        >>
                        >It's in the $_COOKIE array.
                        >--
                        >Rik Wasmus
                        >
                        I tried that and it doesn't seem to work. For instance:
                        >
                        <?php
                        >
                        switch ($_COOKIE["printer"]) {
                        >
                        case A:
                        echo "Hello";
                        break;
                        case B:
                        echo "Yes";
                        break;
                        case C:
                        echo "No";
                        break;
                        case D:
                        echo "Goodbye";
                        break;
                        }
                        ?>
                        >
                        >
                        That doesn't do anything.

                        Do a var_dump($_COOK IE);
                        If nothing is set, the browser probably did not send a cookie, and you'll
                        have to check wether the cookie you're expecting is set correctly.
                        --
                        Rik Wasmus

                        Comment

                        • Jerim79

                          #13
                          Re: Reading a cookie

                          On Feb 7, 11:21 am, Rik <luiheidsgoe... @hotmail.comwro te:
                          Jerim79 <m...@hotmail.c omwrote:
                          On Feb 7, 10:46 am, Rik <luiheidsgoe... @hotmail.comwro te:
                          Jerim79 <m...@hotmail.c omwrote:
                          Okay, so we are going with cookies. The problem I have is that I don't
                          know how to make PHP just read acookie.
                          >
                          It's in the $_COOKIE array.
                          --
                          Rik Wasmus
                          >
                          I tried that and it doesn't seem to work. For instance:
                          >
                          <?php
                          >
                          switch ($_COOKIE["printer"]) {
                          >
                          case A:
                          echo "Hello";
                          break;
                          case B:
                          echo "Yes";
                          break;
                          case C:
                          echo "No";
                          break;
                          case D:
                          echo "Goodbye";
                          break;
                          }
                          ?>
                          >
                          That doesn't do anything.
                          >
                          Do a var_dump($_COOK IE);
                          If nothing is set, the browser probably did not send acookie, and you'll
                          have to check wether thecookieyou're expecting is set correctly.
                          --
                          Rik Wasmus
                          Right, we don't want to set a cookie. EVER. We just want to READ a
                          cookie that we create manually, ourselves. (The goal here is to have
                          the PHP form read a cookie by the name of "printer." The value of
                          "printer" needs to be different on every machine. If PHP sets the
                          cookie, then "printer" would always have the same value and that
                          defeats the purpose. The only way "printer" will have a different
                          value on each computer, is if we create it manually on each machine.
                          We need a way for the PHP form to "identify" which kiosk computer it
                          is talking to.)

                          I know in javascript you can create a cookie manually and have
                          javascript read it. We want to do that in PHP.

                          Comment

                          • Rik

                            #14
                            Re: Reading a cookie

                            Jerim79 <mylek@hotmail. comwrote:
                            Okay, so we are going with cookies. The problem I have is that I don't
                            know how to make PHP just read acookie.
                            >>
                            >It's in the $_COOKIE array.
                            >>
                            I tried that and it doesn't seem to work. For instance:
                            >>
                            >Do a var_dump($_COOK IE);
                            >If nothing is set, the browser probably did not send acookie, and you'll
                            >have to check wether the cookie you're expecting is set correctly.
                            >
                            Right, we don't want to set a cookie. EVER. We just want to READ a
                            cookie that we create manually, ourselves.
                            And the cookie HAS TO BE SET, SOMETIMES, BY AN ARIBTRARY PROGRAM, SCRIPT
                            OR PERSON. If no cookie is set, or you've set it with the wrong
                            parameters, PHP will never receive it.

                            You cannot just expect something exists by just checking wether it exists.
                            I know in javascript you can create a cookie manually and have
                            javascript read it. We want to do that in PHP.
                            No, you just told me you did not want to create it. Get your plan straight.

                            --
                            Rik Wasmus

                            Comment

                            • Jerim79

                              #15
                              Re: Reading a cookie

                              On Feb 7, 11:59 am, Rik <luiheidsgoe... @hotmail.comwro te:
                              Jerim79 <m...@hotmail.c omwrote:
                              Okay, so we are going with cookies. The problem I have is that I don't
                              know how to make PHP just read acookie.
                              >
                              It's in the $_COOKIE array.
                              >
                              I tried that and it doesn't seem to work. For instance:
                              >
                              Do a var_dump($_COOK IE);
                              If nothing is set, the browser probably did not send acookie, and you'll
                              have to check wether thecookieyou're expecting is set correctly.
                              >
                              Right, we don't want to set acookie. EVER. We just want to READ a
                              cookiethat we create manually, ourselves.
                              >
                              And thecookieHAS TO BE SET, SOMETIMES, BY AN ARIBTRARY PROGRAM, SCRIPT
                              OR PERSON. If nocookieis set, or you've set it with the wrong
                              parameters, PHP will never receive it.
                              >
                              You cannot just expect something exists by just checking wether it exists.
                              >
                              I know in javascript you can create acookiemanually and have
                              javascript read it. We want to do that in PHP.
                              >
                              No, you just told me you did not want to create it. Get your plan straight.
                              >
                              --
                              Rik Wasmus
                              When you say "set the cookie" I take that to mean setcookie(). I don't
                              want setcookie(). I want to create the cookie manually. So I can
                              create the cookie called "printer" manually and use
                              $_COOKIE['printer'] to read it?

                              Comment

                              Working...