Reading a cookie

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

    #16
    Re: Reading a cookie

    Jerim79 wrote:
    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
    >>>>informati on 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...@at tglobal.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...@attg lobal.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?
    >
    Jerim,

    You're going to have to set the cookie at some point in order to read
    it. That doesn't have to be right here. As I said - create an admin
    page which is used on install. Set the cookie there with a long
    expiration time. It will be stored on disk for later retrieval.

    Then you'll be able to read the cookie later (from the same domain, of
    course).

    Theoretically it would be possible to set a cookie manually. But you
    would have to know the exact format of the cookie file itself. And that
    can be browser-specific.

    Also ensure your browser is set up to not delete cookies on shutdown (at
    least not for your domain).


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

    Comment

    • Rik

      #17
      Re: Reading a cookie

      Jerim79 <mylek@hotmail. comwrote:
      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?
      Yup, manually, with javascript, with an arbitrary application, no matter.
      As long as a cookie is sent PHP can read it. It does not matter how this
      cookie came to be, just that it's there.


      --
      Rik Wasmus

      Comment

      • Jerim79

        #18
        Re: Reading a cookie

        On Feb 7, 12:11 pm, Rik <luiheidsgoe... @hotmail.comwro te:
        Jerim79 <m...@hotmail.c omwrote:
        When you say "set thecookie" I take that to mean setcookie(). I don't
        want setcookie(). I want to create thecookiemanual ly. So I can
        create thecookiecalled "printer" manually and use
        $_COOKIE['printer'] to read it?
        >
        Yup, manually, with javascript, with an arbitrary application, no matter.
        As long as acookieis sent PHP can read it. It does not matter how this cookiecame to be, just that it's there.
        >
        --
        Rik Wasmus
        When you say "sent" what are you referring to?

        Lets say I create a file on my computer called "printer". Inside that
        file I manually type something like: printer=A. How would I send that
        cookie to the PHP form?

        Comment

        • Rik

          #19
          Re: Reading a cookie

          Jerim79 <mylek@hotmail. comwrote:
          On Feb 7, 12:11 pm, Rik <luiheidsgoe... @hotmail.comwro te:
          >Jerim79 <m...@hotmail.c omwrote:
          When you say "set thecookie" I take that to mean setcookie(). I don't
          want setcookie(). I want to create thecookiemanual ly. So I can
          create thecookiecalled "printer" manually and use
          $_COOKIE['printer'] to read it?
          >>
          >Yup, manually, with javascript, with an arbitrary application, no
          >matter.
          >As long as a cookie is sent PHP can read it. It does not matter how
          >this cookiecame to be, just that it's there.
          >>
          >
          When you say "sent" what are you referring to?
          Read up on how cookies work. A server has to get the (contents of the)
          cookie, how else could you make any decisions on the server based on a
          cookie? When requesting a page from a server, browsers can send the
          contents of available cookies in the header of the HTTP(S) request.
          Lets say I create a file on my computer called "printer". Inside that
          file I manually type something like: printer=A. How would I send that
          cookie to the PHP form?
          The browser takes care of it, and the way and where it stores the cookies
          is hence browser dependant. So to know how to manually create one and
          where to store it you'll have to consult the manual of the browser.
          --
          Rik Wasmus

          Comment

          • Jerim79

            #20
            Re: Reading a cookie

            On Feb 7, 1:03 pm, Rik <luiheidsgoe... @hotmail.comwro te:
            Jerim79 <m...@hotmail.c omwrote:
            On Feb 7, 12:11 pm, Rik <luiheidsgoe... @hotmail.comwro te:
            Jerim79 <m...@hotmail.c omwrote:
            When you say "set thecookie" I take that to mean setcookie(). I don't
            want setcookie(). I want to create thecookiemanual ly. So I can
            create thecookiecalled "printer" manually and use
            $_COOKIE['printer'] to read it?
            >
            Yup, manually, with javascript, with an arbitrary application, no
            matter.
            As long as acookieis sent PHP can read it. It does not matter how
            this cookiecame to be, just that it's there.
            >
            When you say "sent" what are you referring to?
            >
            Read up on how cookies work. A server has to get the (contents of the) cookie, how else could you make any decisions on the server based on a cookie? When requesting a page from a server, browsers can send the
            contents of available cookies in the header of the HTTP(S) request.
            >
            Lets say I create a file on my computer called "printer". Inside that
            file I manually type something like: printer=A. How would I send that
            cookieto the PHP form?
            >
            The browser takes care of it, and the way and where it stores the cookies
            is hence browser dependant. So to know how to manually create one and
            where to store it you'll have to consult the manual of the browser.
            --
            Rik Wasmus
            I guess what I meant to say was "how do you send a cookie to the PHP
            form from the client computer?" If I put the cookie in the location
            where the browser stores all its cookies, would that mean that the
            cookie is accessible by the form, automatically? Does the $_COOKIE[]
            array load all cookies in that browser's cookie location? If not, then
            how do I make my PHP form aware of the cookie?




            Comment

            • VS

              #21
              Re: Reading a cookie

              Jerim79 wrote:
              Lets say I create a file on my computer called "printer". Inside that
              file I manually type something like: printer=A. How would I send that
              cookie to the PHP form?
              Perhaps something like (untested) :

              <?php
              $Now = time();
              $Year=60*60*24* 365;
              if( !isset($_COOKIE['printer']) ){
              if( GetPrinter() ){
              setcookie("prin ter",$Printer,$ Now+$Year);
              }
              }else{
              $Printer = $_COOKIE['printer']
              }
              Function GetPrinter
              {
              global $Printer;
              $Printer = "";
              $FL = @fopen("/xxx/printer", 'r');
              if( $FL ) {
              $buffer = fgets($FL);
              list($key, $Value) = split("=",$buff er);
              if( $key = "printer" ){
              $Printer = $Value;

              break;
              }
              }
              fclose($FL);
              return ($Printer <"");
              }
              ?>

              --
              VS

              Comment

              • Jerim79

                #22
                Re: Reading a cookie

                On Feb 7, 1:30 pm, VS <v...@nospam.bl ueyonder.invali dwrote:
                Jerim79 wrote:
                Lets say I create a file on my computer called "printer". Inside that
                file I manually type something like: printer=A. How would I send that
                cookieto the PHP form?
                >
                Perhaps something like (untested) :
                >
                <?php
                $Now = time();
                $Year=60*60*24* 365;
                if( !isset($_COOKIE['printer']) ){
                if( GetPrinter() ){
                setcookie("prin ter",$Printer,$ Now+$Year);
                }}else{
                >
                $Printer = $_COOKIE['printer']}
                >
                Function GetPrinter
                {
                global $Printer;
                $Printer = "";
                $FL = @fopen("/xxx/printer", 'r');
                if( $FL ) {
                $buffer = fgets($FL);
                list($key, $Value) = split("=",$buff er);
                if( $key = "printer" ){
                $Printer = $Value;
                >
                break;
                }
                }
                fclose($FL);
                return ($Printer <"");}
                >
                ?>
                >
                --
                VS
                I don't know how to make this any clearer. I never ever ever ever ever
                want the PHP code to create any type of cookie, ever. I just want it
                to read the cookie, which I will create manually and place it in a
                directory where the form can access it. Just as in any other language,
                you can open a file outside the program and read its contents. That is
                all I am trying to accomplish here. Think of a C++ program that opens
                a file name text.txt. The program doesn't have to create the file
                first to open it and read it, the file just simply has to exist at the
                specified location.

                Comment

                • Rik

                  #23
                  Re: Reading a cookie

                  Jerim79 <mylek@hotmail. comwrote:
                  I don't know how to make this any clearer. I never ever ever ever ever
                  want the PHP code to create any type of cookie, ever. I just want it
                  to read the cookie, which I will create manually and place it in a
                  directory where the form can access it. Just as in any other language,
                  you can open a file outside the program and read its contents. That is
                  all I am trying to accomplish here. Think of a C++ program that opens
                  a file name text.txt. The program doesn't have to create the file
                  first to open it and read it, the file just simply has to exist at the
                  specified location.
                  Well, you've got the thinking still wrong here.

                  1. Unless accessable by normal network connection, PHP ('the form') cannot
                  under any circumstances access or read the file-system of the client. 't
                  Would be the moment I dump an OS if websrever could view my files like
                  that. PHP is not aware of any other filesystem then it's own (and possible
                  network shares).
                  2. C++ programs do run local (most of the time), so they have access to
                  the file system.
                  3. Normally, the browser is the only application communicating with the
                  server, and can only do so with an HTTP-request. This does not allow the
                  reading of files of the client.


                  Then again, your solution to the problem seems cumbersome. Why go through
                  all that trouble creating a custom made local cookie manually? Just let it
                  be set in an admin interface you'll only have to access once when the
                  computer is moved. Or if everything is within the local network, and ip's
                  are static, store which ip should print where, and change that when you're
                  redecorating. All infintely simpler.
                  --
                  Rik Wasmus

                  Comment

                  • william.clarke

                    #24
                    Re: Reading a cookie

                    I'm not clear on one thing, why don't you want to use setcookie to
                    create the initial cookie, you have control over what goes into the
                    cookie so isn't that manual enough for you.

                    eg. setcookie ("printer", "A", time() + 3600); //Set value of the
                    printer cookie to "A"

                    The cookie is definitely sent to the client browser (I checked my
                    cookie with Mozilla) so I'm not sure what you meant by "I see that in
                    PHP it stores the cookie in
                    memory." Just make sure the setcookie statement comes before any
                    output. Surely this could be the cookie could be set when a user first
                    logs in?
                    Sorry if I'm totally missing the point here.

                    Comment

                    • Rik

                      #25
                      Re: Reading a cookie

                      william.clarke <william.clarke @gmail.comwrote :
                      I'm not clear on one thing, why don't you want to use setcookie to
                      create the initial cookie
                      Please quote and/or reply correctly. I myself have said several times just
                      setting the cookie with PHP is easier. It's the OP that doesn't want it
                      due to some reason either unknown or unconvincing to us...
                      Sorry if I'm totally missing the point here.
                      Long story, long thread :P

                      --
                      Rik Wasmus

                      Comment

                      • Gordon Burditt

                        #26
                        Re: Reading a cookie

                        >I don't know how to make this any clearer. I never ever ever ever ever
                        >want the PHP code to create any type of cookie, ever. I just want it
                        So what does create the cookie? Yeah, I know, "manually". So how
                        do you create a cookie "manually"? To me this suggests disassembling
                        the hard disk and waving a magnet over it VERY CAREFULLY to alter
                        code in the browser. Or pointing a laser by hand at a CD-RW blank to
                        burn a patch file.
                        >to read the cookie, which I will create manually and place it in a
                        >directory where the form can access it.
                        If you create it manually (which is NOT done from the server), there
                        is no such thing as "where the form can access it". A browser
                        usually stores persistent cookies in a file. Or perhaps in the
                        registry. Where that file is and what format it's in will vary
                        with the browser and perhaps the browser version. In most browsers
                        I have seen, the format is not that difficult to figure out. Oh,
                        yes, *CLOSE* all instances of the browser, edit the file, and then
                        restart it. Otherwise your changes may get lost.
                        >Just as in any other language,
                        >you can open a file outside the program and read its contents. That is
                        But browsers do not store cookies in individual files in arbitrary
                        places in the filesystem.
                        >all I am trying to accomplish here. Think of a C++ program that opens
                        >a file name text.txt. The program doesn't have to create the file
                        >first to open it and read it, the file just simply has to exist at the
                        >specified location.
                        Servers do not "open" cookies to read them. If cookies are sent
                        by the browser, they end up in $_COOKIE. If cookies are not sent,
                        they DON'T end up in $_COOKIE. Oh, yes, whether cookies are sent
                        or not depends on the domain of the cookie matched against the
                        domain of the server, and whether the browser takes cookies at all,
                        and, of course, whether the cookie is set in the browser.


                        It seems to me it would be a lot simpler to have a special PHP page,
                        perhaps accessable only by an admin and protected by a password,
                        called "CHANGE MY PRINTER". Its function is to read the form input
                        on which the admin has selected the correct printer, and set the
                        "printer" cookie to whatever the admin requested (using setcookie()).
                        Go to each workstation. Visit the form once for each workstation,
                        setting the appropriate printer. Once done, you're set, (you've
                        done all the "manually" work) and you never have to use that page
                        again, unless the cookie gets lost due to hard disk failure, OS
                        upgrade, users clearing cookies, someone installs a different
                        browser, etc.

                        Comment

                        • P Pulkkinen

                          #27
                          Re: Reading a cookie

                          I want to ask, did you read my last post?
                          Because this thread doesn't seem to progress much.
                          There is a cookie in local machine(that is: browser), if it has been put
                          there in SOME WAY: manually, by javascript or php.
                          And php reads the content of every cookie of that domain when browser is
                          fetching the page. That is possible, because browser sends them to server in
                          page request.
                          So they are all available automatically on $_COOKIE array.
                          So, what's the problem? You want to manually alter the cookie file?
                          Cookie files (in win) seem to be in Documents and settings ->
                          someusersfolder -cookies.
                          They seem to be encrypted, but not in binary. So you can view them in
                          notepad.

                          =============== ====
                          075800campaign
                          campaign

                          1536
                          1300825984
                          29810446
                          2970362304
                          29738026
                          *

                          =============== =====

                          Its looks partially understable, but not wholly. So editing it manually
                          seems impossible - and pointless propably. You can find another way. I
                          suggested a solution earlier, but I didn't got your reply.



                          Comment

                          • Jerim79

                            #28
                            Re: Reading a cookie

                            On Feb 7, 4:45 pm, Rik <luiheidsgoe... @hotmail.comwro te:
                            william.clarke <william.cla... @gmail.comwrote :
                            I'm not clear on one thing, why don't you want to use setcookie to
                            create the initialcookie
                            >
                            Please quote and/or reply correctly. I myself have said several times just
                            setting thecookiewith PHP is easier. It's the OP that doesn't want it
                            due to some reason either unknown or unconvincing to us...
                            >
                            Sorry if I'm totally missing the point here.
                            >
                            Long story, long thread :P
                            >
                            --
                            Rik Wasmus
                            I work for someone who defines my duties. I don't necessarily get to
                            decide how things are done. I was finally able to sell him on an admin
                            page for setting the cookie first. That will work, problem solved.
                            Thank you everyone for the help.

                            This next part is purely for discussion. The example that my boss
                            points to is that once a cookie is set, you close the browser. Open
                            the browser back up, and the browser reads the cookie from somewhere.
                            There must be a seperate "method" for reading a cookie. You don't have
                            to set the cookie everytime, just the first time. It isn't always "set
                            cookie"/"read cookie;" sometimes it is just "read cookie." So let's
                            skip over the initial setting of a cookie. How does the PHP form read
                            the cookie on subsequent trips? I read up a little on Firefox, and I
                            do see where Firefox stores all the cookies and passes the cookies
                            along automatically, so there doesn't seem to be a way to control
                            this. I haven't been able to find out where the cookies are stored or
                            in what format.

                            My boss swears they were able to manually create a cookie previously
                            and have PHP read it, he just doesn't remember how they did it. (When
                            I say manually create a cookie, I mean create a text document on your
                            computer named something like printer.txt and type: printer=1 into it.
                            Then create a PHP script that opens that file on your computer and
                            reads it.) I did this previously with JavaScript, which I understand
                            is a client side language, and PHP is server side.

                            Anyway, problem solved. I feel that I have a better understanding of
                            cookies and how they work, especially under Firefox.

                            Comment

                            • Gordon Burditt

                              #29
                              Re: Reading a cookie

                              >This next part is purely for discussion. The example that my boss
                              >points to is that once a cookie is set, you close the browser. Open
                              >the browser back up, and the browser reads the cookie from somewhere.
                              Browsers have means of saving their state. This is private to the
                              browser. There may not be any public interface for it. It might
                              be in files, in the registry, or whatever. Saved state likely
                              includes cookies, browser history, what page(s) you had open last
                              time so you can restore them this time, anything you can set on
                              preferences pages, and cached content.
                              >There must be a seperate "method" for reading a cookie. You don't have
                              Yes, but it probably isn't a public API. And it WILL vary by
                              browser. And sooner or later it may change in the next version of
                              whatever browser you're using.

                              There's nothing preventing a browser from using anti-tamper techniques
                              on whereever it stores the cookies. You might still be able to
                              delete all the cookies, but not add or change them. I don't know
                              why a browser would bother with this, but some author might.
                              >to set the cookie everytime, just the first time. It isn't always "set
                              >cookie"/"read cookie;" sometimes it is just "read cookie." So let's
                              >skip over the initial setting of a cookie. How does the PHP form read
                              >the cookie on subsequent trips?
                              A *form* is written in HTML (although the HTML may be generated by
                              PHP code). It does not read cookies. The PHP page to which the
                              form is submitted gets the cookie via the HTTP protocol and puts
                              it in $_COOKIE[], where the PHP code can get at it.
                              >I read up a little on Firefox, and I
                              >do see where Firefox stores all the cookies and passes the cookies
                              >along automatically, so there doesn't seem to be a way to control
                              >this. I haven't been able to find out where the cookies are stored or
                              >in what format.
                              I recommend you give up trying and use a reasonably browser-independent
                              approach to set cookies.
                              >My boss swears they were able to manually create a cookie previously
                              >and have PHP read it, he just doesn't remember how they did it. (When
                              >I say manually create a cookie, I mean create a text document on your
                              >computer named something like printer.txt and type: printer=1 into it.
                              >Then create a PHP script that opens that file on your computer and
                              >reads it.)
                              A PHP script does not open files on the client machine.
                              >I did this previously with JavaScript, which I understand
                              >is a client side language, and PHP is server side.
                              If Javascript has an operation to set cookies, that was probably
                              what was used.

                              Comment

                              • Rik

                                #30
                                Re: Reading a cookie

                                Gordon Burditt <gordonb.72lkh@ burditt.orgwrot e:
                                <snip>Cookie storing an sending is browser and confuguration
                                specific</snip>
                                >I did this previously with JavaScript, which I understand
                                >is a client side language, and PHP is server side.
                                >
                                If Javascript has an operation to set cookies, that was probably
                                what was used.
                                Cookies can equally be set by javascript as with the the return header.
                                The browser might allow it different rights/ttl/etc.. then a cookie set by
                                the header, but the fact remains it's still stored and send back by the
                                browser, it's just told to do so by javascript.
                                --
                                Rik Wasmus

                                Comment

                                Working...