By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,828 Members | 801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,828 IT Pros & Developers. It's quick & easy.

Reading a cookie

P: n/a
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.

Feb 6 '07 #1
Share this Question
Share on Google+
29 Replies


P: n/a

"Jerim79" <my***@hotmail.comkirjoitti
viestissä:11**********************@v45g2000cwv.goo glegroups.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.
Feb 6 '07 #2

P: n/a
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.
Feb 6 '07 #3

P: n/a
On Feb 6, 9:03 am, "P Pulkkinen"
<perttu.POISTATAMA.pulkki...@POISTATAMA.elisanet.f iwrote:
"Jerim79" <m...@hotmail.comkirjoitti
viestissä:1170773276.017695.162...@v45g2000cwv.goo glegroups.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.

Feb 6 '07 #4

P: n/a
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.
Feb 6 '07 #5

P: n/a
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.
js*******@attglobal.net
==================
Feb 6 '07 #6

P: n/a
On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attglobal.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 thecookiemanually, 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...@attglobal.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.

Feb 7 '07 #7

P: n/a
Jerim79 wrote:
On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attglobal.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 thecookiemanually, 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...@attglobal.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.
js*******@attglobal.net
==================
Feb 7 '07 #8

P: n/a
On Feb 7, 10:17 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Jerim79 wrote:
On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attglobal.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 thecookiemanually, 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...@attglobal.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...@attglobal.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?

Feb 7 '07 #9

P: n/a
Rik
Jerim79 <my***@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
Feb 7 '07 #10

P: n/a
On Feb 7, 10:46 am, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@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.
--
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.

Feb 7 '07 #11

P: n/a
Rik
Jerim79 <my***@hotmail.comwrote:
On Feb 7, 10:46 am, Rik <luiheidsgoe...@hotmail.comwrote:
>Jerim79 <m...@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.
--
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($_COOKIE);
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
Feb 7 '07 #12

P: n/a
On Feb 7, 11:21 am, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@hotmail.comwrote:
On Feb 7, 10:46 am, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@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.
--
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($_COOKIE);
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.

Feb 7 '07 #13

P: n/a
Rik
Jerim79 <my***@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($_COOKIE);
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
Feb 7 '07 #14

P: n/a
On Feb 7, 11:59 am, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@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($_COOKIE);
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?

Feb 7 '07 #15

P: n/a
Jerim79 wrote:
On Feb 7, 10:17 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Jerim79 wrote:
>>On Feb 6, 3:50 pm, Jerry Stuckle <jstuck...@attglobal.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 thecookiemanually, 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...@attglobal.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...@attglobal.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.
js*******@attglobal.net
==================
Feb 7 '07 #16

P: n/a
Rik
Jerim79 <my***@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
Feb 7 '07 #17

P: n/a
On Feb 7, 12:11 pm, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@hotmail.comwrote:
When you say "set thecookie" I take that to mean setcookie(). I don't
want setcookie(). I want to create thecookiemanually. 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?

Feb 7 '07 #18

P: n/a
Rik
Jerim79 <my***@hotmail.comwrote:
On Feb 7, 12:11 pm, Rik <luiheidsgoe...@hotmail.comwrote:
>Jerim79 <m...@hotmail.comwrote:
When you say "set thecookie" I take that to mean setcookie(). I don't
want setcookie(). I want to create thecookiemanually. 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
Feb 7 '07 #19

P: n/a
On Feb 7, 1:03 pm, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@hotmail.comwrote:
On Feb 7, 12:11 pm, Rik <luiheidsgoe...@hotmail.comwrote:
Jerim79 <m...@hotmail.comwrote:
When you say "set thecookie" I take that to mean setcookie(). I don't
want setcookie(). I want to create thecookiemanually. 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?


Feb 7 '07 #20

P: n/a
VS
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("printer",$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("=",$buffer);
if( $key = "printer" ){
$Printer = $Value;

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

--
VS
Feb 7 '07 #21

P: n/a
On Feb 7, 1:30 pm, VS <v...@nospam.blueyonder.invalidwrote:
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("printer",$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("=",$buffer);
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.

Feb 7 '07 #22

P: n/a
Rik
Jerim79 <my***@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
Feb 7 '07 #23

P: n/a
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.

Feb 7 '07 #24

P: n/a
Rik
william.clarke <wi************@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
Feb 7 '07 #25

P: n/a
>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.

Feb 8 '07 #26

P: n/a
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
www.inoa.fi/yrityshaku/
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.

Feb 8 '07 #27

P: n/a
On Feb 7, 4:45 pm, Rik <luiheidsgoe...@hotmail.comwrote:
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.

Feb 8 '07 #28

P: n/a
>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.

Feb 9 '07 #29

P: n/a
Rik
Gordon Burditt <go***********@burditt.orgwrote:
<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
Feb 9 '07 #30

This discussion thread is closed

Replies have been disabled for this discussion.