4:08 pm Saturday, July 31, 2010
     
SERVER TRANSFER COMPLETE. UNDER CONSTRUCTION.
            Search About Contact Home
Creating Your First ASP Page Tutorial
AaronOutpost : ASP / Tutorials / ASP 101 / Security

ASP 101: Security
By: Aaron B. Copyright AaronOutpost.com

 

    This is part 5 of 6 of ASP 101 by AaronOutpost.com. If you are unsure of what we may be talking about in the tutorial, view the previous parts.

So far we have created your first ASP page, we have defined a value, displayed it on the page, as well as discussed some date and time functions. We then learned about If, Then, and Else statements. We are now going to take a look on how to log some data such as a users IP address.

Let's begin.

 

Part 5:
SECURITY

START YOUR PAGES

Security measures are always a must on scripts you will soon create. Logging IP address is primary. 

You can Dimension variables anywhere in the script you wish as I have done in the middle of this one. I also separated variable with a comma. This is a quick and easy way when you are not going to place comments after the dimension.

Dim Temp, IpAddress

Next, I define the variable Temp. At this time I am going to request information from the server using one of it's predefined variables as I mentioned before. To get this information I will use Request.ServerVariables and then HTTP_X_FORWARDED_FOR which will retrieve whether or not the user using a proxy. If so, it will strip it and get their true IP address.

Temp = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

Next I will use an If Then statement. You may want to view some Visual Basic books if you are unfamiliar with If Then statements. The next statement says that If the variable Temp is not empty then the IpAddress is equal to what we defined Temp to be which was the stripped IP. 

If Temp<>"" Then

IpAddress = Temp

But, what if they are not using a proxy or firewall or website to load a page. They are just using a browser. We use the Else state to define what the script will do if Temp is empty. So, Else the IpAddress is equal to the server variable REMOTE_ADDR which is the remote computers IP Address. Then we use the End If statement to end the If statement. and once again use the response.write command to display what we have found the user's Ip address to be. You will also noticed I included html and server variables all in one line of the response.write command by using the & sign.

Else

IpAddress = Request.ServerVariables("REMOTE_ADDR")

End If


You will now notice that I have closed the Script with
%>  This now allows me to type html coding. However I still wanted to display the IP address so you can start script again and put an equals sign. This will type out the value of that variable. So we type of the variable of the IPAddress that we obtained.

'Close the server script
%>

<br><br>My IP Address Is: <%= IpAddress %> </body> </html>

 

 

CONGRATULATIONS!!!

Now, you have completed part 5 of 6 Learning ASP 101 by AaronOutpost.com.

Open Viewable Example
Continue to part 6: Include Files

<html>

<head>

<title>My First ASP Page</title>

</head>

<body bgcolor="#FFFFFF" text="#000000" link="#003300" vlink="#006600" alink="#689577">

 

<%

'Dimension variables

Dim MyVariable 'Comment on what this variable holds

 

'Define a value for the MyVariable
MyVariable = "I am learning ASP! This is my first programmed variable!"
%>

<br><br>
<font face="Arial" size="2" color="#000000">
<%
= MyVariable %><br><br>

Server Date & Time is: <%= Now() %><br><br>

Server Time is: <%= Time() %> <br><br>

Server Date is: <%= Date() %><br><br>

Current Hour is: <%= Hour(Now()) %><br><br>

Current Minute is: <%= Minute(Now()) %><br><br>

Current Second is: <%= Second(Now()) %><br><br>

vbGeneralDate: <%= FormatDateTime(Now(), 0) %><br><br>

vbLongDate: <%= FormatDateTime(Now(), 1) %><br><br>

vbShortDate: <%= FormatDateTime(Now(), 2) %><br><br>

vbLongTime: <%= FormatDateTime(Now(), 3) %><br><br>

vbShortTime: <%= FormatDateTime(Now(), 4) %><br><br>

<% Dim intHour 'Variable to hold hour intHour = Hour(Now()) If intHour > 12 Then
'If hour is under 5 pm then afternoon
If intHour < 17 Then %>
Good Afternoon!
<% Else %>
Good Evening!
<% End If
Else %>
Good Morning!
<% End If %>

<%

Dim Temp, IpAddress

Temp = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

If Temp<>"" Then

     IpAddress = Temp

     Else

     IpAddress = Request.ServerVariables("REMOTE_ADDR")

End If


%>

<br><br>My IP Address Is: <%= IpAddress %>

</font>

</body> </html>

 


AaronOutpost : ASP / Tutorials / ASP 101 / Security


Random_Image
News & Updates

ASP Inline Calendar 3.9 (January 5, 2008)
Future Home of News & Updates (January 5, 2008)

 

Photo Special

Schedule an appointment

Available in & around:
Centreville VA, Spotsylvania VA,
Summersville WV, & Charleston WV
.

  • NAME YOUR PRICE
    • Email your:
    • Event
    • Hours Needed
    • Photos Needed
    • Disks or Prints
    • and Price You're Willing To Pay
ASP Inline Calendar

$100 Installation Special

PROFESSIONAL INSTALLATION OF YOUR ASP INLINE CALENDAR. REDUCE THE HASSLE, LET US INSTALL YOUR ASP INLINE CALENDAR. SEND A FORMAL REQUEST FOR INSTALLATION WITH SERVER ACCESS INFORMATION. WE WILL NEED FTP ACCESS ALONG WITH CONTROL PANEL ACCESS.

Purchase A Calendar
Information
Demo
Ask A Question

User must provide ftp access to server. Installations are not guaranteed. We work with your service provider to get your calendar installed.

 

Centreville, VA      -      Spotsylvania, VA      -      Charleston, WV      -      Summersville, WV

© Copyright AaronOutpost.com 2010. All rights reserved.