Search This Blog

Saturday, 16 October 2010

CSS study notes: Reset the default css

Recently, I read a word called css reset. What is css reset? I understand that as a reset css, that is, reset the default style. Some elements in the HTML tag and there is a default property value, When writing a css, in order to avoid duplication in css to define them, we need to reset the default style (css reset). I find an article on the survey about css reset, can be used to see the proportion of investigations.



There is a more comprehensive summary of css reset, css reset cited a variety of wording, which can be a reference.

Then I also see the two Chinese sites, with Firebug to see them, press F12, how to write css reset.

1. Taobao.com


<----! html {

overflow-x:auto;

overflow-y:scroll;

}

body, dl, dt, dd, ul, ol, li, pre, form, fieldset, input, p, blockquote, th, td {

font-weight:400;

margin:0;

padding:0;

}

h1, h2, h3, h4, h4, h5 {

margin:0;

padding:0;

}

body {

background-color:#FFFFFF;

color:#666666;

font-family:Helvetica,Arial,sans-serif;

font-size:12px;

padding:0 10px;

text-align:left;

}

select {

font-size:12px;

}

table {

border-collapse:collapse;

}

fieldset, img {

border:0 none;

}

fieldset {

margin:0;

padding:0;

}

fieldset p {

margin:0;

padding:0 0 0 8px;

}

legend {

display:none;

}

address, caption, em, strong, th, i {

font-style:normal;

font-weight:400;

}

table caption {

margin-left:-1px;

}

hr {

border-bottom:1px solid #FFFFFF;

border-top:1px solid #E4E4E4;

border-width:1px 0;

clear:both;

height:2px;

margin:5px 0;

overflow:hidden;

}

ol, ul {

list-style-image:none;

list-style-position:outside;

list-style-type:none;

}

caption, th {

text-align:left;

}

q:before, q:after, blockquote:before, blockquote:after {

content:"";

}----!>


2. Baidu.com

<---! body {

font-family:arial,helvetica,sans-serif;

font-size:13px;

font-size-adjust:none;

font-stretch:normal;

font-style:normal;

font-variant:normal;

font-weight:normal;

line-height:1.4;

text-align:center;

}

body, ul, ol, dl, dd, h1, h2, h3, h4, h5, h6, p, form, fieldset, legend, input, textarea, select, button, th, td {

margin:0;

padding:0;

}

h1, h2, h3, h4, h5, h6 {

font-size:100%;

font-weight:normal;

}

table {

font-size:inherit;

}

input, select {

font-family:arial,helvetica,clean,sans-serif;

font-size:100%;

font-size-adjust:none;

font-stretch:normal;

font-style:normal;

font-variant:normal;

font-weight:normal;

line-height:normal;

}

button {

overflow:visible;

}

th, em, strong, b, address, cite {

font-style:normal;

font-weight:normal;

}

li {

list-style-image:none;

list-style-position:outside;

list-style-type:none;

}

img, fieldset {

border:0 none;

}

ins {

text-decoration:none;

} ----!>


Css reset with those reference, and then according to their actual situation, write a perfect line with your site css reset.

Tuesday, 12 October 2010

Create dynamic ASP page using a template

For the template, I think we may have some concepts. Many of the template in the MS word, probably good design layout, you just fill in your own words to those occupying the character just fine. Here is the template probably mean that a relatively stable part of the page fixed, the other part of the root of different situations different content in the input. In fact, DreamWeaver also has templates, but the static content can only be filled manually, and here about the dynamic content automatically populated.

First of all, let me explain why use template file. Sometimes, the template will give you the layout of web features and more complete concept. When you see the Word template format, you will know the final layout looks like, so ASP does.

For example, you can keep the ASP statement, and use different templates to create different page styles. In this way, you do not have to create pages for each different styles, which to save a lot of time. Moreover, the template file to make it easier to browse the page code. You can only focus on HTML, while the ASP is no need to to manage. Also, templates is very simple, you definitely get to know quickly. I will use a database - a very broad use of the product table. Including product ID, names, photos, and summary. Here is the Access database structure:

File name - myDatabase.mdb

table name - Product

ID

Autonumber

FullName
txt - 100 chars max

PicURL
txt - 255 chars max

Descriptions

PicCaption
txt - 50 chars max

Set up a database, we can start building the template file. This file is the skeleton of each page. So in the end, it looks like is like this:

Product Name:
%name%
Description:

%description%

This picture was taken: %date%

product ID: %prod%


This is a simple template. Save it for the template.tmp, in the ASP page will be a reference to it. Those % around the field in the database and the corresponding meaning. Consider the following ASP code, how to read into the template and database files, then output HTML pages what we want to.

It's just open the template file, read each line in sequence, and then read in the database field values instead of the actual template that% img%,% name% tag. In some applications, such as real-time news, so it may be more convenient.

Friday, 8 October 2010

ASP website code and use MD5 encryption

When design Asp website,always need involve encrypted data which is stored in the database, such as registered users, user name and password storage. If just use codes stored in the database directly, once the database is trespassed by malicious program of hacked, it can be directly seen the user's user name and password, cause to leakage of sensetive information.

To solve the above problem, the solution is stored in the database after the data encryption, common idea is the user name codes stored, then encrypted password storage. Certainly, encryption algorithms have certain requirements that should be a one-way encrypted information, irreversible, can not be restored by other algorithms.

Among the algorithms, md5 algorithm is the most famous and commonly used encryption algorithm. md5 encryption algorithm is based on a variable-length binary value, the method is mapping into a fixed length hash value. If there are any changes to the encrypted file, the map will change the hash value. This feature is not only the key used to encrypt database data, also used to verify the download data whether the packet is identical with the published data packets, mainly used in CD image verification system.

md5 algorithm implementation (md5.asp) has become a common subroutine contains the md5 algorithm function. For the encrypted data, you can call the file contains and md5 () function to implement data transfer before the encrypted and storage. Specific form as follows:

1. Register user encryption

\'includes md5 file

... ...

password=md5(ltrim(request.form("password"))) \'use md5 encryption (sql server)

password=md5(trim(request.form("password"))) \'use md5 encryption (Access)

... ...

2. Process user login

\'inc md5 file
... ...

dim rs

UserName1=request.form("UserName")

password=md5(trim(request.form("password")))    \'through md5 encryption to get pw(Access)

verifycode=request.form("verifycode")

set rs=server.createobject("adodb.recordset")

sql="select * from admin where username=\'"&username1&"\'"

rs.open sql,conn,1,3 \'Generated record set

  if password<>rs("password") or verifycode<>session("verifycode") then

  response.write "

The runat = server line tells us that it was executed on the server. So it can not use msgbox () function, can not use the document.Write method.

Full method is:

<---!SCRIPT LANGUAGE="VBScript" RUNAT="Server"---!>

Sub Application_OnStart
... ...
End sub

Sub Application_Onend
... ...
End Sub

Sub session_OnStart
... ...
End Sub

Sub session_Onend
... ...
End Sub


When you visit a website. If it is html based, then the program will not run because there is no application, session objects occur.

If it is ASP based, the server firstly checks the root www directory or virtual directory to see whether there is a global.asa file. If so, then run the program to the corresponding code

How to remind the user once a failure to object in the session?
First of all, I will discuss how to reminder after failure. Does it need remind? Why do not use direct detection value of session ("**").
** means you want to test whether the failure of its session ("**") value. This is not good, because the people who come firstly may be null of its session ("**").

So, we will look at where will be applied for. The most obvious example is the login page, if you use session to store the user's login status. You have to tell him whether the failure of login.

Now This is a sample for my assignment:

<---!SCRIPT LANGUAGE="VBScript" RUNAT="Server"---!>
Sub Application_OnStart
Application.Lock
Application("site_name") = "Welcome to Australia Wine Distributors Network--AWDN official website"
Application("user_online") = 0
Application("template") = "template"
Application("conn") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("data.mdb")&";"
Application.UnLock
End Sub

Sub Session_OnStart
Session.Timeout=20

Session("userid") = "0"
Session("username") = "0"
Session("level") = "0"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Application("conn")
set objRs = Server.CreateObject("ADODB.RecordSet")
szSql = "select top 1 * from [count]"
objRs.open szsql,conn,1,3
if not objRs.eof then
objRs("count") = objRs("count")+1
else
objRs.addnew
objRs("count") = 1
end if
objRs.update
objRs.close
set objRs = nothing
set conn = nothing
End Sub

Sub Session_OnEnd
Session("userid") = "0"
Session("username") = "0"
Session("level") = "0"
End Sub

Sub Application_OnEnd
Application.Lock
Application("user_online") = 0
Application.UnLock
End Sub
<---!/SCRIPT---!>


When user login to database, s welcome will be appeared. A record will be in database such as yser's operation and session. If user doesn't use it more than 20 minutes (Session.Timeout=20), system will lock and require user login again.

Note: ---! need be removed.