Im a programmer

Unknown's avatar

I'm just a student that loves programming I know my English is not so good but I'm practicing:D Just wanted to share my little experience(I know it's useless for you experts:P)

Homepage: https://imaprogrammer.wordpress.com

Spammers

Hello everyone!

Today I had a little problem with a spammer.

He was requesting a page like 3 o 4 times per second.

And I found about it after one of my tables(stats) got overloaded by data so I contacted my host (The host I’m using is really good and fast and has a really good support, thanks ipage) and they restored my database.

First I emptied stats table and then blocked the spammer’s ip with .htaccess.

Then I thought about preventing spammers accessing my site too fast.

So I wrote this piece of code.

I know It’s really simple but I guess it gives the idea to some newbies like me.

For the table:
CREATE TABLE `Ips` (
`ip` varchar(15) NOT NULL,
`accessTime` int(11) NOT NULL,
`accessPage` varchar(10) NOT NULL
)

And at the header of you site:

$ip=$_SERVER[‘REMOTE_ADDR’];

$con = mysql_connect(“localhost”,”user”,”pass”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“your_db”, $con);

$max=2;
$interval=3; //these two parameters mean that the a user can access your site maximum 2 times in 3 seconds
$timeLow = time()-$interval;
$timeNow = time();

$accessNum=mysql_query(“SELECT * FROM Ips WHERE accessTime > ‘$timeLow’ AND ip=’$ip'”);
if(mysql_num_rows($accessNum) > 2){
mysql_query(“INSERT INTO Ips (ip,accessTime,accessPage) VALUES (‘$ip’,0,’$accessPage’)”);//I used this to check know who accessed my site too fast(just with searching the table for accessTime=0
mysql_close($con);
die(‘You are accessing this site too fast’);
}
$accessPage=substr($_SERVER[“SCRIPT_NAME”],strrpos($_SERVER[“SCRIPT_NAME”],”/”)+1);
mysql_query(“INSERT INTO Ips (ip,accessTime,accessPage) VALUES (‘$ip’,’$timeNow’,’$accessPage’)”);
mysql_close($con);

Well you can add more columns to database for more details(like date).

I hope this article be a little help for you:D

, , , , ,

Leave a comment

Hello again!

In Spain I started to work with css and some JavaScript Plugins.

Well in these three years i was just learning and learning

I learned linux, C, Java, ADA(I guess no one has heard about it:D), and Ajax and I finally left my beloved language VB6 and moved to VB.net

Now almost everyday I’m programming

Most of the time I’m searching for functions in the internet for VB.net and Ajax

The program I’m making with VB.net needed to download a html page and then convert a table to dataset

I searched for it but the answer was a component and the cost was near $150

So I decided to do it myself

After Learning about how VB.net works with html I understood that it was so much easier than I though

I just need to make a do while until for the InnerText of all td’s until I read the value I want.(since the page wasn’t standardized and the tags didn’t have anyname)

And about a script that I’m working with.

It has a header file for all the pages, so any JavaScript needed in search.php will be included in index.php as well.

So I decided to pass the name of the page to smarty and in the smarty for each JavaScript put an if to check if it’s a right page to include this JavaScript or no.

I will tell you more about a little experience I have:D

Leave a comment

Hello Programmers!

Hi everyone!

I guess I have to start with a introduction.

I’m a student in Spain but my originality is Iranian(I lived there until 2007).

The first time i started programming.

I started with VB6 even VB 7.0 was already released back then.

With the first line of a code i started to love programming and I started to progress in VB6

After writing few programs in VB6 for my school and my friends I heard one of my friends that web programming is even more fun

Well I though I’m fine just with VB6 and not going to learn anything else

But when after a year(I started programming with VB6 in 2004) Microsoft stopped supporting VB6 and I didn’t have anymore ideas for programming in VB6(I just wanted new ideas and didn’t like old ideas)

I didn’t do a lot until 2005(I did a little program with c++ and assembly for analyzing object movements in the camera)

Then I saw php

I really loved this programming language

It was really easy to understand and I started Web programming(right now I’m modifying a script that works with php, mysql and smarty)

I remember I had a friend that was talking about Ajax all the time

I really couldn’t understand what he was saying since I didn’t have any experience in javascript

In 2007 I moved to Spain.

I’m sure you are tired by now:P

I will leave the rest for tomorrow.

Tell me what you think about me.

Thanks:D

Leave a comment

Design a site like this with WordPress.com
Get started