Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

About WebServer Application

Posted on 1999-07-26
9
Medium Priority
?
132 Views
Last Modified: 2010-04-04
I want to make web server application, but how could i make a cookie and read it?
Is there a forum example? pls mail to:
cheng-jian@163.net
0
Comment
Question by:chengjian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1391231
0
 
LVL 1

Author Comment

by:chengjian
ID: 1391232
I have seen that
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1391233
So what's the problem then?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:chengjian
ID: 1391234
for my poor englisn, not finish test yet, sorry:(
0
 
LVL 1

Author Comment

by:chengjian
ID: 1391235
i finished .
but i still not clear about those cookies related function and procedure, could discribe them for me?
and is there a forum example?
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 1391236
Here is what I did a few weeks ago:

// This method checks if a cookie has been received and takes the
// appropriate action.
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  if Request.CookieFields.Count = 0 then
    // redirect
    Response.SendRedirect('/login.htm')
  else begin
    // display the cookie contents
    Response.Content := Request.CookieFields.Text;
  end;
end;

// This method tries to plant the received ContentField values into a cookie
procedure TWebModule1.WebModule1WebActionItem2Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  MyCookies: TStringList;
  i: integer;
begin
  MyCookies := TStringList.Create;
  // Filter the name and passwork values out of the ContentFields
  with MyCookies do begin
    i := Request.ContentFields.IndexOfName('name');
    if i <> -1 then
      Add(Request.ContentFields.Strings[i]);
    i := Request.ContentFields.IndexOfName('password');
    if i <> -1 then
      Add(Request.ContentFields.Strings[i]);
  end;
  if MyCookies.Count >= 2 then begin
    // Plant the cookie
    with Response do begin
      SetCookieField(MyCookies, '', '/', Now + 30, false);
      Content := 'Welcome ' + MyCookies.Values['name'] + ', your cookie has been planted';
    end;
  end;
  MyCookies.Free;
end;

// This method deletes a cookie
procedure TWebModule1.WebModule1WebActionItem3Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  with Response do begin
    SetCookieField(Request.CookieFields, '', '/', -1, false);
    Content := Request.CookieFields.Values['name'] + ', your cookie has been deleted';
  end;
end;


Regards,

Epsylon.
0
 
LVL 1

Author Comment

by:chengjian
ID: 1391237
wait one day pls:-)
0
 
LVL 1

Author Comment

by:chengjian
ID: 1391238
hi, a day is not needed:)
discribe these pls:
SetCookieField(Request.CookieFields, '', '/', -1, false);
1.What's all these params means?
2.Response.Content := Request.CookieFields.Text; //what would be return in this example?
Could u explain all replated object/mathod/property for me? just a short discription, thanx

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1391239
SetCookieField(Request.CookieFields, '', '/', -1, false);

parameters:
1) the cookie list
2) the domain, '' (empty string) means local host
3) the path within the domain the cookie is set for, '/' means the entire domain
4) the expiration date on which the cookie expires, -1 deletes the cookie right away
5) whether or not to use a secure connection to send the cookie to the server



Response.Content := Request.CookieFields.Text;

In this line the webserver app returns the received cookie to the client as text. It's just to see what happens when the the webserver app receives a cookie.

Eps.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question