How Can I Send a cookie to Client, but client none request.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
darnis
Forum Newbie
Posts: 4
Joined: Fri Jun 14, 2002 2:45 am
Location: China

How Can I Send a cookie to Client, but client none request.

Post by darnis »

hi all,

there is a problem that I can't see. I am writing a dynamic page use PHP, I want to send a cookie to client and at this time the client don't request, ex.

the client A have connected to Server S1, Now Client B connect to S1, And Client B send a message to S1, Now I want to implement that S1 can notify Client A a information that client B join in on S1's own initiative.

Is this possible? Thanks .
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I'm not sure I understand what you're asking. You can't send a cookie unless someone goes to your website and you can't have a cookie do anything other than store information which you can retrieve on the person's next visit to your site. Users can also stop cookies from being set so it's never good to rely on them for anything non-trivial. That said I don't think what you are asking here needs cookies involved at all.

What exactly are you trying to do? When you say "Client B send a message to S1" do you mean through a webpage form? If so then when the form is submitted you can have a bit of scripting that notifies Client A through e-mail.

Really to be of much help I think we need a bit more information.

Mac
User avatar
darnis
Forum Newbie
Posts: 4
Joined: Fri Jun 14, 2002 2:45 am
Location: China

Sorry , My En is poor. But I mean is....

Post by darnis »

I want to notify the client A when Client B connect to Server S1, It's must be real time, online, then Email isn't a good solution. i.e. , A and B is online, B connect to Server S1 that may be tell Server by FORM and otherwise. A has none request, Now can the server send a cookie to client A ?

The Server can easy send a cookie to a Client When then client access the server. But now the Client is online , It visited the server a moment ago, and the session not broken; at this time the Client B visit the same server, now i need the server can send a cookie to Client A. :-)

Thank U..
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The server cannot send a cookie to Client A unless Client A returns to the website. A cookie can also not notify Client A that Client B is online - cookies can only store data.

Mac
User avatar
darnis
Forum Newbie
Posts: 4
Joined: Fri Jun 14, 2002 2:45 am
Location: China

Maybe I should say this:

Post by darnis »

<b>If the Client A stay in website persist</b> , and this time Client B conncect to server (server knows ), Now function SetCookie can send a cookie to Client B, But How can I send a cookie to Client A at this time? Maybe this process wouldn't implement, But i want to get the answer.
[/i]
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To set a cookie on Client A's computer when Client B is on the website you need:
  • To be able to log Client B's existance to a file or database,
  • Have Client A still on your website and active (going to new pages, refreshing pages),
  • Be able to identify Client A,
  • Have script included on every page that checks if the computer is Client A's and if it is whether or not Client B is online and set the cookie if he is.
The fact still remains that cookies can't do anything other than store data - a cookie cannot in itself notify Client A that Client B is online. You need additional script to run that will show a notice on the page, or send an email or something. If you do that then the cookie is pointless - doesn't need to be set because you can show a notice without it.

If you are looking for a way of having storing the fact that Client B's on-line, mark him active in a database or text file something that your server can access that is independent of Client A or B.

Mac
User avatar
darnis
Forum Newbie
Posts: 4
Joined: Fri Jun 14, 2002 2:45 am
Location: China

Oh...

Post by darnis »

Thank u,
I want to check the Cookie by JScript on client A(loop) that My original meaning. Then I can implement that Server notify the Client A, and then Client A send a request to Server ....
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Give up twigletmac, I don't think he is getting the point :cry:
NikolasTSR
Forum Newbie
Posts: 3
Joined: Mon Sep 16, 2002 3:07 pm

Post by NikolasTSR »

Hi darnis

1. "to set a cookie" you must sent the information before any other information (html or php code). Witch means that to make "A" aware of "B", "A" must reload his page, or you must refresh it.

2. Refreshing a users page enery now is not a good idea. The never come back.

3. You can use frames and refresh a piece of users page. (I just came up with this, I haven't tried yet)

4. As others allready said, with cookies you only store info to someones computer for a given time. So if you set a cookie on "A"'s computer that "A" is loged in, how can "B" get this info??

5. use an "active user" table istead. Have your users login and isert them to the table. If you refresh the frame (I said before) every now end then you can print there the contents of the "active table". All the users logged in will know how else is logged in.

6. you have to find a way to delete them from the table when the leave your site. You can make them click a "log off" button but what if someone "is on a hurry" and just close the window? Here you must use cookies.

I hope this will help you, if you haven't found an other way allready.
Post Reply