What is hot linking?
Bandwidth theft or “hotlinking” is direct linking to a web site’s files (images, video etc). Have your ever noticed your site is having small amount of visitors comparing to the bandwidth it is consuming??
It may happen because other websites are linking your image files, videos and other resources direclty from your site without uploading them in their server. This gives them the benefit that they donot need to expense their bandwidth from their host because they are stealing that from your site.
So to prevent abuse of your bandwidth you must prevent hot linking so that other sites cannot directly link off your files.
To do this you must use an apache mod rewrite code in your “.htaccess” file. This techinque will prevent direct linking to image video and other high bandwidth consuming files being linking directly by any other host than yours. When resource files are directly linked from other host it will redirect all those links to a small image file saying “No hot linking!”.
How to do this?
Add this code in you “.htaccess” file.
1
2
3
4
| # Prevent Hot Linking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?dscripts\.cc/ [nc]
RewriteRule .*\.(gif|jpg|png|zip|swf)$ img/hotlink.gif [nc] |
Lets see what happens in this code.
This two line below sets an condition for what to do if the referrer page is not from “dscripts.net”.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?dscripts\.cc/ [nc]
And this line below say what would be returned file for the file with gif, jpg, png, zip or swf extensions. If the any other site link your any resource then a fake image at “img/hotlink.gif” will be returned to them.
4
| RewriteRule .*\.(gif|jpg|png|zip|swf)$ img/hotlink.gif [nc] |
burhan Mod Rewrite Add new tag
Search engines consider http://dscripts.net and http://www.dscripts.net as different site. So when your pages are accessible with both www and non www url your pages from referer sites and search engines break into two parts. Thus you get only half benifit from search engines.
So to optimize your search enginge referals to maximum you must use either only www or non www urls by redirecting one to another. In most in this case websites redirects non www url to www url.
To do put this code at the top of your .htaccess file.
# Non www url to www url
RewriteCond %{HTTP_HOST} !^www\.dscripts\.net
RewriteRule (.*) http://www.dscripts.net/$1 [R=301,L]
Dont forget to change the name of your domain from the avobe code.
burhan Mod Rewrite Add new tag
Microsoft Access database lets you store information without installing any database server. It is handy for small applications when your do not need to put too much entries in database and making application for the most novice level of users. C# is a great tool to create user friendly applications using Access Database.
So if you want to connect your C# application with Microsoft Access database just follow the following…
The first you need is to use OLEDB connector.
First we need to use oledb connector namespace.
using System.Data.OleDb;
Now we need to create an instance of OleDbConnection object. The following will be the connection string required to use as parameter of OleDbConnection instance object
private string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=contact.mdb;Jet OLEDB:Database Password=123456";
Here contact.mdb is the microsoft access database file located at the same directory to the exe file.
Now we can look at the whole code at once.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
using System.Xml.Serialization;
namespace ConsoleApplication2
{
public class Program
{
private static OleDbConnection con;
static void Main()
{
try
{
con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=contact.mdb;Jet OLEDB:Database Password=123456"); // connection string change database name and password here.
con.Open(); //connection must be openned
OleDbCommand cmd = new OleDbCommand("SELECT * from contact", con); // creating query command
OleDbDataReader reader = cmd.ExecuteReader(); // executes query
while(reader.Read()) // if can read row from database
{
Console.WriteLine(reader.GetValue(1).ToString() + " = " + reader.GetValue(3).ToString()); // Get column 1 and column 3 value and print
}
}
catch(Exception ex)
{
Console.WriteLine("Ex: "+ex); // shows exception message in console if any errors occured
}
finally
{
con.Close(); // finally closes connection
}
}
}
}
Hope you’ll find it helpful. See you Ya!
burhan C#, Database C#, Database, Microsoft Access, OleDB
Mod rewrites lets you to create search engine friendly urls. By enabling its power you can rank your site higher in search engines. So what to do if your apache server doesnt have mod rewrite enabled by default?
Simply go to Apache installation folder. Then open conf/httpd.conf with notepad and find the line
#LoadModule rewrite_module modules/mod_rewrite.so
Now uncomment the line by removing the ‘#’ from the front of this line.
LoadModule rewrite_module modules/mod_rewrite.so
Restart Apache Server. From now on mod rewrite will be active.
burhan Mod Rewrite Mod Rewrite, SEO
I searched Internet a lot before I could figure out how to connect to mysql database server using C#. This is the one that worked in my favour.
To connect to mysql database using C# first you should have to download a small program called mysql connector .net from MySQL’s official site. Click here to visit this link to download mysql connector .net
After installing connector. Open Visual Studio and then create a new console application project. Now you have to add the reference of the namespace for mysql connection.
Go to project>Add Reference…
In the .NET tab you shall find a component named “MySql.Data”. Select this component and click “Add”.
Add the Name space at the top of your code.
using MySql.Data.MySqlClient;
In this string change your server, database name, user id and password
public static string db = "server=localhost;database=abc;uid=root;password=";
Now finally use this code to select data from your database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace ConsoleApplication3
{
class Program
{
public static string db = "server=localhost;database=dsc;uid=root;password=";
static void Main(string[] args)
{
try
{
MySqlConnection con = new MySqlConnection(db);
con.Open(); // connection must be openned for command
MySqlCommand cmd = new MySqlCommand("Select * FROM `dsc_scripts`", con);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString("id") + ": " + reader.GetString("name") + " - " + reader.GetString("hs"));
}
}
catch (Exception ex)
{
Console.WriteLine("Error: "+ex);
}
finally
{
con.Close();
}
}
}
}
Hope this will be helpful for you.
burhan C# C#, MySql