Hi everyone,
I have written a php script that enables users of our lan network to send sms messages to mobile phones.
Now i want to limit the sending of sms to 2 sms per day and per ip.
can anyone help to set this up?
i thought about a plain file solution as the number of clients in our lan is limited to about 50. but if you have an easy solution with database....
i need some help to get this started.
i appreciate your ideas!
Maximilian
Limit Access to X hits per day and IP
Moderator: General Moderators
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
I would just make a DB table with two or three fields:
IPaddress
SMSsent
Day // optional
All you have to do is log the IP address and the number of times an SMS has been sent (SMSsent). If SMSsent=2, then no more messages will be permitted. You can either have PHP reset the table each day, clearing out entries (via a DELETE command), or just log the current day as well (hence the Day field).
IPaddress
SMSsent
Day // optional
All you have to do is log the IP address and the number of times an SMS has been sent (SMSsent). If SMSsent=2, then no more messages will be permitted. You can either have PHP reset the table each day, clearing out entries (via a DELETE command), or just log the current day as well (hence the Day field).
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
It depends upon the Database. If you are using a MySQL db, with table sms and columns num_sms and user_IP, you can do something like:
To get the data from the DB
To put the data into the db:
As I previously mentioned, you can either do a db DELETE to clear out the database each day, or use a date field to keep track of days.
To get the data from the DB
Code: Select all
<?php
$user_IP=$_SERVER['REMOTE_ADDR']; // look up Predefined variables in the manual
$qry_num_sms="SELECT num_sms FROM sms WHERE user_IP='".$user_IP."'";
// $conn is a database connection. look up mysql_connect and mysql_select_db
$result=mysql_query($qry_num_sms,$conm) or die(mysql_error());
// number of messages sent from IP. mysql_num_rows used to make sure there is a row present
$num_sms=(mysql_num_rows($result)>0)?mysql_result($result,0):0;
// look into mysql_result, mysql_fetch_row, mysql_fetch_assoc, and mysql_fetch_object for different ways to use query results
?>Code: Select all
<?php
// after user sends SMS
$user_IP=$_SERVER['REMOTE_ADDR'];
$qry_num_sms="SELECT num_sms FROM sms WHERE user_IP='".$user_IP."'";
$result=mysql_query($qry_num_sms,$conm) or die(mysql_error());
$num_rows=mysql_num_rows($result);
$num_sms=($num_rows>0)?mysql_result($result,0):0;
$num_sms++;
$qry_increment_sms=($num_rows>0)?"UPDATE sms SET num_sms='".$num_sms."' WHERE user_IP='".$user_IP."'"
: "INSERT INTO sms(user_IP,num_sms) VALUES('".$user_IP."', '".$num_sms."')";
mysql_query($qry_increment_sms,$conn) or die(mysql_error());
?>