Posted by: thebeanproject on: June 19, 2009
Last month, I was told to create a script that will download files automatically from the server and upload it to another server. I was having a hard time on how to figure this out. Fortunately, I ran across Auto FTP Manager. This program allows you to connect to any FTP server and automatically upload and download files or synchronize directories. Since every week they have different filenames on the downloaded files, so I have to create a Batch file that will get files from the download directory and rename it according to the filenames on the other webserver. Below is the batch file that I created and saved it as runit.bat.
@ECHO OFF
set totcount=0
for /f “usebackq delims=” %%a in (`dir /b *.pdf`) DO (
call :s_do_sums “%%a”
):s_do_sums
set /a totcount+=1
IF EXIST %totcount%.pdf (
DEL %*
)
REN %* %totcount%.pdf
Using Auto FTP Manager you could schedule and automate your file transfers. Therefore, I used a scheduled task to run my batch file one hour after the scheduled ftp download is ran. After that I scheduled another ftp upload to another server in one hour timespan as well.
Posted by: thebeanproject on: June 19, 2009
There are many web browsers out there and some programmers are having a headache because of browser compatibility. Sometimes you just want to tell the web to execute another script if the user is using a specific browser. Here is a script that will help you determine what kind of browser does the user use.
<script language=”JavaScript”>
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || “An unknown browser”;
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || “an unknown version”;
this.OS = this.searchString(this.dataOS) || “an unknown OS”;
},
searchString: function (data) {
for (var i=0; i<data.length; i++) {
var dataString = data[i].string; var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{
string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{
// for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "IE",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{
// for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};
BrowserDetect.init();
alert(BroswerDetect.Browser);
</script>
Thanks to QuirksMode that make this possible. For more detail information click here
Posted by: thebeanproject on: June 19, 2009
A favicon (short for favorites icon), also known as a website icon, shortcut icon, url icon, or bookmark icon is a 16×16 pixel square icon associated with a particular website or webpage. Browsers that provide favicon support typically display a page’s favicon in the browser’s Address bar and next to the page’s name in a list of bookmarks. Browsers that support a tabbed document interface typically show a page’s favicon next to the page’s title on the tab. — Favicon Wiki
<link REL=“SHORTCUT ICON” HREF=“http://yoursitedotcom.here/favicon.ico”>
You could also create a PNG or GIF for your FAVICON, but it will not work on Internet Explorer. I would recommend using a .ICO file.
Posted by: thebeanproject on: June 19, 2009
There are several ways of blocking specific IP Addresses. In this article I will talk about blocking IP Address using PHP, ASP, ASP.NET, and JavaScript.
PHP Code:
$blockedIP = array();
$blockedIP[] = “x.x.x.x”;
$blockedIP[] = “x.x.x.x”;
$blockedIP[] = “x.x.x.x”;
$blockedIP[] = “x.x.x.x”;$incomingIP = $_SERVER["REMOTE_ADDR"];
for($i=0; $i<count($blockedIP); $i++){
if($blockedIP[$i] == $incomingIP){
echo “<script>alert(‘you are not allowed to visit this site anymore’);</script>”;
header(“location: http://www.google.com”);
break;}
}
ASP Code:
Dim blockedIP(2) ‘fixed size array
blockedIP(0) = “x.x.x.x”
blockedIP(1) = “x.x.x.x”
blockedIP(2) = “x.x.x.x”Dim incomingIP
incomingIP = Request.ServerVariables(“REMOTE_ADDR”)For i=0 to UBound(blockedIP)
if(blockedIP(i) = incomingIP) then
response.write(“<script>alert(‘you are not allowed to visit this site anymore’);</script>”)
response.redirect(“http://www.google.com”)
exit forend if
Next
ASP.NET C# Code:
ArrayList blockedIP = new ArrayList();
blockedIP.Add(“x.x.x.x”);
blockedIP.Add(“x.x.x.x”);
blockedIP.Add(“x.x.x.x”);string incomingIP = Request.UserHostAddress;
foreach (string x in blockedIP){
if (x == incomingIP){
response.write(“<script>alert(‘you are not allowed to visit this site anymore’);</script>”);
response.redirect(“http://www.google.com”);
break;}
}
JavaScript Code:
There is a MAJOR FLAW using JavaScript to blocked specific ip address. If the JavaScript is turned off this script will NOT WORK!!.
<script language=”javascript” type=”text/javascript”>
var blockedIP = new Array();
blockedIP[0] = “x.x.x.x”;
blockedIP[1] = “x.x.x.x”;
blockedIP[2] = “x.x.x.x”;//PHP –> <?php echo $_SERVER["REMOTE_ADDR"]; ?>
//ASP –> <%= Request.ServerVariables(“REMOTE_ADDR”) %>
//ASP.NET –> <%= Request.UserHostAddress %>
var ip = ‘<?php echo $_SERVER["REMOTE_ADDR"]; ?>‘;for(var i=0; i<blockedIP.length; i++){
if(blockedIP[i] == ip){
alert(“you are not allowed to visit this site anymore”);
window.location = “http://www.google.com”;
break;}
}
</script>