Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void Page_Load(object sender, EventArgs e)
- {
- // get user ip
- string host = Dns.GetHostName();
- IPHostEntry ip = Dns.GetHostEntry(host);
- string strClientIP = Context.Request.ServerVariables["REMOTE_ADDR"];
- lblUserIP.Text = strClientIP;
- // connect to database and see if user exsists, and check if he is banned..
- string connection = WebConfigurationManager.ConnectionStrings[0].ConnectionString;
- SqlConnection coN = new SqlConnection(connection);
- SqlCommand sql;
- sql = new SqlCommand("SELECT * FROM tblACESS WHERE ip = '" + lblUserIP.Text + "'", coN);
- coN.Open();
- SqlDataReader readME = sql.ExecuteReader();
- if (!readME.HasRows)
- {
- readME.Close();
- sql.CommandText="INSERT INTO tblACESS (ip, date, hits, access) VALUES ('" + lblUserIP.Text + "',getdate(),'1','true')";
- sql.ExecuteNonQuery();
- coN.Close();
- }
- else
- {
- readME.Close();
- sql.CommandText = "SELECT * FROM tblACESS WHERE ip = '" + lblUserIP.Text + "'";
- readME = sql.ExecuteReader();
- int hits = 0;
- bool hasACCESS = true;
- while (readME.Read())
- {
- hits = (int)readME["hits"];
- hasACCESS = Convert.ToBoolean(readME["access"]);
- }
- hits++;
- readME.Close();
- sql.CommandText = "UPDATE tblACESS SET date = getdate(), hits = '" + hits.ToString() + "' WHERE ip = '" + lblUserIP.Text + "'";
- sql.ExecuteNonQuery();
- coN.Close();
- if (!hasACCESS)
- {
- Response.Redirect("http://tinyurl.com/69tmmqq");
- }
- }
- }
Add Comment
Please, Sign In to add comment