Fix for Internet Explorer 5.5/6/7/8 to render HTML5 documents and websites normally. Place this code into the
of document. ... Reveal Code
Delphi: Delay without blocking of the main thread
Function delays program logic execution for a number of miliseconds, The GUI and Windows messages will continue to work. ... Reveal Code
//------------------------------------------------------------------------------
// Provides a waiting (delay) for a given count of MSec (Sec*10^-3).
// The message processing will continue to work.
procedure Delay(MSec: Cardinal);
var
BeginTime: Cardinal;
begin
BeginTime := GetTickCount;
repeat
Application.ProcessMessages;
until Cardinal(Abs(GetTickCount - BeginTime)) >= MSec;
end;
Delphi: Version of EXE or DLL file
Function returns version of Exe/Dll file as "1.2.3.4" string ... Reveal Code
//------------------------------------------------------------------------------
// Returns version from file resource as string "1.2.3.4"
function GetFileVersion(const AFileName: string): string;
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(AFileName), Dummy);
GetMem(VerInfo, VerInfoSize);
try
GetFileVersionInfo(PChar(AFileName), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
Result := IntToStr(dwFileVersionMS shr 16);
Result := Result + '.' + IntToStr(dwFileVersionMS and $FFFF);
Result := Result + '.' + IntToStr(dwFileVersionLS shr 16);
Result := Result + '.' + IntToStr(dwFileVersionLS and $FFFF);
end;
finally
FreeMem(VerInfo, VerInfoSize);
end;
end;
Force the browser to download the file instead of opening it ... Reveal Code
$file_text = 'Some text here';
if (isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
Header('Content-Type: application/force-download');
else
Header('Content-Type: application/octet-stream');
Header('Accept-Ranges: bytes');
Header('Content-Length: ' . strlen($file_text));
Header('Content-disposition: attachment; filename="downloaded_file.txt"');
echo $file_text;
exit();
Determination of the country by IP using geoplugin.net OR ipinfodb.com. Will return the country code in "Alpha-2 ISO 3166-1" format (a two-char code) ... Reveal Code
function get_country($ip_addr) {
$curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0';
$url = 'http://www.geoplugin.net/php.gp?ip=' . $ip_addr;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch1);
$geoplugin = unserialize($result);
if ($geoplugin[geoplugin_countryCode] != '') {
return $geoplugin[geoplugin_countryCode];
} else {
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip_addr);
$ch = curl_init();
$curl_opt = array(
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => $curlopt_useragent,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 1,
CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
);
curl_setopt_array($ch, $curl_opt);
$content = curl_exec($ch);
if (!is_null($curl_info)) {
$curl_info = curl_getinfo($ch);
}
curl_close($ch);
if (preg_match('{
Country : ([^<]*)}i', $content, $regs))
$country = $regs[1];
return $country;
}
}