Gossamer Forum
Home : General : Perl Programming :

Write IP address to a file!

Quote Reply
Write IP address to a file!
I hope someone can help me...

I am allowing people to send FREE text messages from my site to any cell phone...but I only want them to be able to do it 5 times before they get a message saying they now have to pay...can ANYONE help me do this?

I use a form on a html page to submit the info into a perl script that then sends the message.

I would like a sub in the perl file that writes the persons IP address to a file along with an ID which has the value of 1. Then if that person sends another text message, the ID will increase by one, and then when it gets to 5 they get a warning from then on.

So in a log file, the sub would make something like:
127.0.0.1|1

Then if the person from 127.0.0.1 sent another message, it would overwrite the current record and change it to...
127.0.0.1|2

Can someone provide me with the code for this?....Thanks so much!

Paul.

From Paul Wilson.
http://www.audio-grabber.com
On error resume next..
Quote Reply
Re: Write IP address to a file! In reply to
Hi Paul,

Sorry but I have a Dilemna for you. You want to do this but how can you determine if your users have static or dynamic IP's. For your static IP users your plan will work, though your dynamic IP users will get many free messages...You may want to use cookies instead? If your users don't accept cookies though, then they can't use your system...Another possibility is to setup a login system of some kind.

I hope this is helpful though I know it wasn't what you were looking for.

Quote Reply
Re: Write IP address to a file! In reply to
Yeah I thought of that after I posted the message!

Could you tell me how I can get the script to set a cookie as well as log the IP so it will eliminate most people from sending too many messages.

If someone has a dynamic IP and cookies turned off then I will have to put up with them sending many messages, but by setting a cookie and logging the IP, I will be able to prevent most!

Thanks....Id use the login idea but I want it to be easy for people to use and dont want them to have to login each time!

Another thought.....could I not just use cookies and then give an error message if they dont have cookies turned on...

So if they try to send a message with cookies off, the script says "sorry..you can only send a message with cookie on"...and then when they turn them on, they are able to send a message, and also the cookie is set to limit the number of messages they send.

Thanks


From Paul Wilson.
http://www.audio-grabber.com
On error resume next..
Quote Reply
Re: Write IP address to a file! In reply to
Whilst we are on the subject....I have another script that sends operator logos to cell phones.

On a html page, a list of images are shown with a radio button next to each, they then select the image they want to send. This value gets passed through the perl script. However, before it can be sent, the image has to be turned in to hex code. I have a bit of code that turns the image into hex, but I dont know where to put the code as it keeps giving me an internal server error.

Here is the code:

open(F, "$IMG") || die $!;
$s = $hx = ""
while (read(F, $s, 1) > 0 {
$hx .= sprintf("X", ord($s));
}
close F;

This BB has messed with the code so the ("X", ord($s)); bit above is supposed to be a percent sign then 02X not a little square!

Here is the perl file used...


#!/usr/bin/perl

use CGI;
use IO::Socket;
$cgi = new CGI;

$USERNAME = "username";
$PASSWORD = "password";
$TEST = 1;
$numbers = $cgi->param("N");
$MC = $cgi->param("MC");
$IMG = $cgi->param("IMG");
$message =~ s{([&\+%# =])}{hx($1)}ge;
$sock = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "www.smsproccessorsite.com",
PeerPort => 80 );
if (defined($sock)) {
$sock->autoflush(1);
$str = "USERNAME=$USERNAME&PASSSWORD=$PASSWORD&MC=$MC&IMG=$IMG";
$len = length($str);
$sock->print("POST /cgi-bin/form.cgi HTTP/1.0\n");
$sock->print("Host: www.sms-wap.com\n");
$sock->print("Content-type: application/x-www-form-urlencoded\n");
$sock->print("Content-length: $len\n\n");
$sock->print("$str\n");
while ($_ = <$sock>) {
if (/^(\d+)/) { $result = $1; last; } }
$sock->close;

HTML FOR SUCCESS PAGE HERE

} else {

THEN HTML FOR ERROR PAGE

exit 0;

sub hx {
my($char) = @_;
return sprintf "%%%X", ord($char);
}


I have altered the values of the variables slightly as I dont want people stealing and using the code, but the bulk is there.

Basically the variable $str is what is sent to the SMS processors website and they process the info. It is sent in a URL. Eg when the user submits their info, the URL shown in the browser contains all the info to be sent to the processor.

But the $IMG variable has to be changed to hex so that in the URL it does not contain IMG=myimage.gif....it has to be IMG=3434723947695273652935769...loads of hex code.

So before the Info is sent to my processors, the myimage.gif has to be replaced with the hex code and then added to the URL

Am I making sense?....Sorry if I have waffled a lot!

Thanks!


From Paul Wilson.
http://www.audio-grabber.com
On error resume next..