Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.10.28;
Скачать: CL | DM;

Вниз

Как забросить Cookie на определенное время? Не получается   Найти похожие ветки 

 
Vlad Oshin ©   (2007-09-27 12:32) [0]

следующее должно закидывать кук, рабочий в течении expC:tdatetime; времени.

procedure SetCookie(var Response: TWebResponse; nameC,valueC:string; expC:tdatetime; run:boolean);
begin
 with (Response.Cookies.Add) do
 begin
   name := nameC;
   Value := valueC;
   Secure := False;
   Expires := expC;
   if run then Response.Cookies.WebResponse.SendResponse;
 end;
 log("SetCookie(var Response: TWebResponse; nameC,valueC:string; expC:tdatetime; run:boolean);",nameC+" "+valueC);
end;


а так беру из кука и смотрю чему равно login / pasword (тестирую)
(ShowLogPage; - предлагает перерегистрироваться)

GLOGIN:=Request.ContentFields.Values["LOGINF"];
GPASSWORD:=Request.ContentFields.Values["PASSWORDF"];
if GLOGIN<>""
 then SetCookie(Response, "LOGINF",GLOGIN, dt+ddt, false)
 else GLOGIN:=GetCookie(Request, "LOGINF");
if GLOGIN="" then response.Content:=ShowLogPage;
if GPASSWORD<>""
 then SetCookie(Response, "PASSWORDF",GPASSWORD, dt+ddt, false)
 else GPASSWORD:=GetCookie(Request, "PASSWORDF");
if GPASSWORD="" then response.Content:=ShowLogPage;

 response.Content:=VerLogin;


как считываю
Function GetCookie(Request: TWebRequest; nameC:string):string;
begin
 with (Request) do
 begin
   result:=CookieFields.Values[nameC];
 end;
 log("GetCookie(Response: TWebResponse; nameC:string):string;",result);
end;


вот в чем проблема - кук должен работать час (ddt=1час) , но работает и на след. день.


 
clickmaker ©   (2007-09-27 13:11) [1]

Response.Headers["Set-Cookie"] := Format("%s=%s; path=/; expires=%s",
 [strCookieName, strCookieValue, DateTimeToStr(IncHour(Now))]);


 
Vlad Oshin ©   (2007-09-27 13:58) [2]

Response.Headers
нет у меня такого св-ва.. (d7)

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
 Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

Handled:=false;
тогда все работает правильно..(в моем понимании)

из хелпа
This example shows an OnAction event handler that adds a cookie to the response message. The cookie stores the current authorization information. This allows the current client to revisit the URL without resupplying a password for a limited period (1 day). Because a password is sensitive information, the cookie can only be sent on a secure connection.

procedure TWebModule1.PasswordCookieActionAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

begin
 Handled := False; { adding a cookie does not handle the request }
 with Response.Cookies.Add do
 begin
   Name := "LastPassword";
   { Set the LastPassword cookie to the current authorization }
   { Or, if no authorization was supplied this time, carry over }
   { the authorization from the LastPassword cookie of the request }
   Value := Request.Authorization;
   if Value = "" then
     Value :=  Request.CookieFields.Values("LastPassword");

   Secure := True; { be sure to use a secure connection!!!!}
   Expires := Now + 1; { this cookie expires in one day }
 end;
end;


1.Indicates whether the request has been handled.
2.Indicates whether the incoming request has been handled.
т.е. не  был обработан..

ничего не понимаю..


 
Vlad Oshin ©   (2007-09-27 15:06) [3]

не не работает вообщето :)
короче, все неправильно

SetCookie(Response, "LOGINF",GLOGIN, dt+ddt, false)
не нужно dt, совсем

SetCookie(Response, "LOGINF",GLOGIN, ddt, false)
так работает нормально


 
Vlad Oshin ©   (2007-09-27 15:54) [4]

блинн..
нет, если я тупой - так и скажите - ты тупой

что-то вообще никакой зависимости не вижу...
он может работать минуту, может 5 минут, может 10
может через несколько секунд перезапросить логин
что ему вообще надо.. кофе со сливками или с разбегу с ноги...



Страницы: 1 вся ветка

Текущий архив: 2007.10.28;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.015 c
15-1190773341
Slider007
2007-09-26 06:22
2007.10.28
С днем рождения ! 26 сентября 2007 среда


2-1191432426
artkil
2007-10-03 21:27
2007.10.28
Строки TListView


2-1191402557
Washington
2007-10-03 13:09
2007.10.28
Выбор принтера


6-1168705868
vidiv
2007-01-13 19:31
2007.10.28
сетевой select в INDY


1-1186729609
vamp_avp
2007-08-10 11:06
2007.10.28
Передача данных в Word