| |
| Posted by Can Alpay Çiftçi (canalpay) in reply to Can Alpay Çiftçi (canalpay) | PermalinkReply |
|
Can Alpay Çiftçi (canalpay)
| Biraz kopya ile yazdım.Konsoldan çalıştırdım ve doğru sonucu verdi:
module library.cookie;
import std.process; // getenv
import std.string;
//import library.convertToUTF8;
import std.uri;
import library.fixedString;
string[string] cookie()
{
string[string] endCookie;
string cookie = getenv("HTTP_COOKIE");
endCookie=fixedString(decode(cookie));
return endCookie;
}
void setCookie(string name, string data, long expiresIn = 0, string path = null, string domain = null, bool httpOnly = false)
{
string[] hd;
string cookie = name ~ "=";
cookie ~= data;
if(path !is null)
cookie ~= "; path=" ~ path;
if(expiresIn != 0)
cookie ~= "; expires=" ~ printDate(expiresIn);
if(domain !is null)
cookie ~= "; domain=" ~ domain;
if(httpOnly == true )
cookie ~= "; HttpOnly";
responseCookies ~= cookie;
if(responseCookies !is null && responseCookies.length > 0) {
foreach(c; responseCookies)
hd ~= "Set-Cookie: " ~ c;
}
std.stdio.writeln(hd);
}
// Buna gerek yok ancak
//std.datetime.ToUnixTime işlevini kullanamadım.
/*
* uniz zaman değeri veren bir işlev gerekiyor.
*/
string printDate(long date) {
return "Sun, 06 Nov 2011 08:49:37 GMT";
}
private string[] responseCookies;
void clearCookie(string name, string path = null, string domain = null) {
setCookie(name, "", 1, path, domain);
}
Ancak şuanki unix zamanını döndüren bir işlev bulamadım. std.datetime'da toUnixTime işlevi vardı ancak kullanınca hata veriyordu. Tanımlanmamış diyordu.Ancak datetime eklenemedi diye bir hatada yoktu. Anlamadım.
--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]
|