Welcome to WebmasterWorld Guest from 220.127.116.11
Forum Moderators: open
I finally have the chance to sit down and begin this small tutorial in ASP Cloaking.
Before beginning, I will state some brief definitions.
Cloaking Ė The ability to display web content to one user while displaying different content to another without having to change the page URL.
You can get a better explanation here [searchengineworld.com].
Robots/ Spiders Ė Iíll let SearchEngineWorld.com [searchengineworld.com] explain this one as well.
Now, letís start talking about how IP-Based Cloaking works.
IP-Based Cloaking works by grabbing the IP Address of a robot/spider or user (users = humans throughout this whole thread). Then it takes the IP Address and compares it with a database full of robot/spider IPís. If it finds a match, the script then pulls up the specified content for that robot/spider. If it does not find a match, the script pulls up the user content.
Thatís the concept of IP-Based Cloaking. You can write the script with almost any language. Most people do it in Perl. While some do it in PHP or even ASP. The point is it can be done with any server-side scripting language. All you need to do is grab the IP Address, check it with a database and determine whether or not the IP matches. After thatís determined give them the specified content. That sounds easy enough. The hard part is getting your database filled with spider info. You can go about doing that either of two ways. One is search and find the info yourself or buy it from someone else. Once you have the robot/spider database ready you can start building the script. All of this takes time. First you build it then you maintain it. Both the script and the database have to be kept up. But thatís another story.
OK, this first post is just to get anyone that is not familiar with IP-Based Cloaking to get an understanding of how it works. Check out the links given here and ask away. You should also read this thread here [webmasterworld.com].
Now we will talk a little about the script
Below are the variables we will be using and there values.
' Set Variables
Dim spider_check, ipaddress, data_source
' Request the IP Address
ipaddress = Request.ServerVariables("REMOTE_ADDR")
' This SQL statement checks the IP address with IP address of spiders in your DB
spider_check = "select ipaddress from data where ipaddress = '" & ipaddress & "'"
' This SQL statement uses the spiders IP address to grab that spiders information.
spider_info = "select * from data where ipaddress = '" & ipaddress & "'"
'This is where the path to the directory that holds your Database goes
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ Server.MapPath("/directory/path/accessDB/cloak.mdb")
The above is pretty basic. You declare the variables then you set up the values. You have your SQL statements that will be used to pull information from the database and at the bottom you have a variable holding the path to the database.
The one to pay close attention to is the one in red
ipaddress = Request.ServerVariables("REMOTE_ADDR")
This variable holds the IP-Address. Here we are using one of the properties of the Request Object, the ServerVariables collection. Anytime you need to find out anything about your server, this is the collection you will be using. What goes inside the ( ) is what is called the server environment variable. In this case we are using ďREMOTE_ADDRĒ. This will grab the IP Address of the user requesting the page. Now we have the users IP Address.
This is one of the reasons ASP is in the cloaking business. In the next post I will talk about making the connection to the database and checking the IP-Address we have obtained with the database.
In this post I will talk about
First things first. On the last post we set the variables we needed with the SQL queries we will be using. We also set the variable holding the path to the database. Now we will use that path and one of the first SQL statements.
First we start with connecting to the database.
' Create the instance of Connection Object and then open the database
Set con = Server.CreateObject("ADODB.Connection")
Here we open the path that we set earlier in the data_source variable. Here we use the Server Object. We use this object to gain access to properties on the server. Now with the Server Object we will use the CreateObject Method to create an instance of a server component. Inside the CreateObject ( ) we will use the connection object. ďADODB.ConnectionĒ. This sets the con variable to become the connection object. Then, below the ďSet con =Ē we use con.Open. This opens a connection to the database by using the data_source variable. The data_source variable tells the con variable where the database that itís supposed to connect to is.
O.K., we have now connected to the database. Now we will execute our first SQL statement.
Set rs = con.Execute (spider_check, , 1)
Again, the con variable is used along with Execute method. In the parenthesis we have the spider_check variable that holds our first SQL statement. The number 1 is there to tell it to stop when it finds a match(Simply put).
Now that all that code has been executed we will grab the info that our SQL statement got and use it.
But that will have to wait until the next post. I apologize for the slow wait but Iíve been really busy with work and all. But I will get to it ASAP. Scouts Honor :)