i'm trying to make a simple script - review and help please

They have: 1,587 posts

Joined: Mar 1999

ok, all i'm trying to do is write a script that will record an ip then write over that ip when another one comes in

#!/usr/local/bin/perl
#

$ip = "path to file";
#path of ip log file

#####

# Gets the input
read(STDIN, $ENV{'REMOTE_ADDR'});

#enter the correct path or variable, writes over
open (LOG, ">$ip");

# prints ip on file
print LOG "$ENV{'REMOTE_ADDR'}";

# closes file so it can't be read and written at same time
close (LOG);

#believe this ends script
exit;

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

They have: 1,587 posts

Joined: Mar 1999

ok, i've added some stuff. what i'm try to do is record the last ip. then if the new ip is the same as the last one they get redirect to page 1 and if the ip's are differ they get redirected to page 2. all i seem to be able to do no matter if the ip is the same or differ is redirect to $differ. any help would be appreciated.

#!/usr/local/bin/perl
#

$ip = "path";
#path of ip log file

$same = "sameipredirect";
# url if same ip

$differ = "differipredirect";
# url if differ ip

#####

#enter the correct path or variable, opens file
open (LOG, "$ip");

if ($ENV{'REMOTE_ADDR'} == @ip) {

# closes file so it can't be read and written at same time
close (LOG);

# redirects to same ip page
print "Location: $same\n\n";

} else {

# closes file so it can't be read and written at same time
close (LOG);

#enter the correct path or variable, writes over
open (LOG, ">$ip");

# prints ip on file
print LOG "$ENV{'REMOTE_ADDR'}";

# closes file so it can't be read and written at same time
close (LOG);

# redirects to differ ip page
print "Location: $differ\n\n";

}

#believe this ends script
exit;

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

They have: 1,587 posts

Joined: Mar 1999

well, i think i figured it out. could you check over it and let me know if it's gonna blow my computer up or if it can be optimized?

thanks in advance

#!/usr/local/bin/perl
#

$ipfile = "pathtologfile";
#path of ip log file

$same = "sameipurl";
# url if same ip

$differ = "differipurl";
# url if differ ip
#####

#enter the correct path or variable, opens file
open (LOG, "$ipfile");

$ip = <LOG>;

if ($ENV{'REMOTE_ADDR'} eq $ip) {

# closes file so it can't be read and written at same time
close (LOG);

# redirects to same ip page
print "Location: $same\n\n";

} else {

# closes file so it can't be read and written at same time
close (LOG);

#enter the correct path or variable, writes over
open (LOG, ">$ipfile");

# prints ip on file
print LOG "$ENV{'REMOTE_ADDR'}";

# closes file so it can't be read and written at same time
close (LOG);

# redirects to differ ip page
print "Location: $differ?$ENV{'QUERY_STRING'}\n\n";

}

#believe this ends script
exit;

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.