Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Reading a cookie

 
Goto page 1, 2
   Database Forums (Home) -> PHP RSS
Next:  Table driven, massively parallel RDBMS in the fut..  
Author Message
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 1) Posted: Tue Feb 06, 2007 6:47 am
Post subject: Reading a cookie
Archived from groups: comp>lang>php (more info?)

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.

 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 2) Posted: Tue Feb 06, 2007 7:22 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 6, 9:03 am, "P Pulkkinen"
wrote:
> "Jerim79" kirjoitti
> viestissä:1170773276.017695.162...@v45g2000cwv.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.

 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 3) Posted: Tue Feb 06, 2007 4:50 pm
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.RemoveThis@attglobal.net
==================
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
P Pulkkinen

External


Since: Jan 15, 2007
Posts: 5



(Msg. 4) Posted: Tue Feb 06, 2007 5:03 pm
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Jerim79" kirjoitti
viestissä:1170773276.017695.162470@v45g2000cwv.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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
P Pulkkinen

External


Since: Jan 15, 2007
Posts: 5



(Msg. 5) Posted: Tue Feb 06, 2007 5:08 pm
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> 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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
P Pulkkinen

External


Since: Jan 15, 2007
Posts: 5



(Msg. 6) Posted: Tue Feb 06, 2007 5:49 pm
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 7) Posted: Wed Feb 07, 2007 7:19 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 6, 3:50 pm, Jerry Stuckle wrote:
> 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... RemoveThis @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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 8) Posted: Wed Feb 07, 2007 8:41 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 10:17 am, Jerry Stuckle wrote:
> Jerim79 wrote:
> > On Feb 6, 3:50 pm, Jerry Stuckle wrote:
> >> 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....RemoveThis@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....RemoveThis@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?
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 9) Posted: Wed Feb 07, 2007 8:53 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 10:46 am, Rik wrote:
> Jerim79 wrote:
> > 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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 10) Posted: Wed Feb 07, 2007 9:32 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 11:21 am, Rik wrote:
> Jerim79 wrote:
> > On Feb 7, 10:46 am, Rik wrote:
> >> Jerim79 wrote:
> >> > 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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 11) Posted: Wed Feb 07, 2007 10:00 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 11:59 am, Rik wrote:
> Jerim79 wrote:
> >> > 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?
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 12) Posted: Wed Feb 07, 2007 10:47 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 12:11 pm, Rik wrote:
> Jerim79 wrote:
> > 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?
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 13) Posted: Wed Feb 07, 2007 11:17 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Jerim79 wrote:
> On Feb 6, 3:50 pm, Jerry Stuckle wrote:
>> 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... RemoveThis @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.
jstucklex RemoveThis @attglobal.net
==================
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 14) Posted: Wed Feb 07, 2007 11:21 am
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 1:03 pm, Rik wrote:
> Jerim79 wrote:
> > On Feb 7, 12:11 pm, Rik wrote:
> >> Jerim79 wrote:
> >> > 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?
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Jerim79

External


Since: Nov 21, 2006
Posts: 11



(Msg. 15) Posted: Wed Feb 07, 2007 12:04 pm
Post subject: Re: Reading a cookie [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 7, 1:30 pm, VS wrote:
> 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.
 >> Stay informed about: Reading a cookie 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
find a cookie by part of it's name - Hi all, cookies are stored in an array called $HTTP_COOKIE_VARS right ? Is it possible to find a cookie if you know part of it's name ? For example the cookiename is firstname and I want to check all cookies that start with "first" in ...

PHP EMail Form and set cookie - Hi, Being new to PHP & cookies, I am looking to write an email form, where a user can choose their name from a drop down list, fill in the content of the email and hit send and the email will be from that user. Then the next time they visit the pag...

loosing cookie values in new pages - Dear all, We are using cookie base access management in our business intranet portal. We are setting user level cookies at the time of successfull login in the system, and after login we are checking the cookie 'user id' and 'page id'; if user has..

i can't set a cookie? Or is it a Windows problem? - This site was working: http://www.thesecondroad.org/ Now I'm told people are unable to create new accounts or log in. One theory: It seems that cookies are not being set. Our beta testers missed this bug, because the code was working at some point, an...

Reading from txt file - I have the following code: <?php $username = $_POST['username']; $myFile = "clientlist.txt"; $fp = fopen($myFile, 'r'); $content = fread( $fp, filesize( $myFile ) ); $inputString = $username; $arrFp = file( $myFile ); // Open the data file ...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Goto page 1, 2
Page 1 of 2

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]