Jump to content

quick question about logging ip addresses


iMakeAngry

Recommended Posts

So, to keep this as short as possible, I am almost done making a website that lets visitors send already-made text messages to people. I just paid for hosting for the site, and they told me that I can only send 100 messages in one hour. This is fine as I was already intending on setting limits per ip address.

 

So, I've set up MySQL and everything else works correctly. My only problem is that on the test script I've been working on over the weekend doesn't successfully check to see if an ip address exists in the database.

 

Let me try and better explain what I need to do:

I need the visitor's ip address to be logged on to the database the first time that they send a message in a day. (This part works.)

 

But before it logs their ip address, it needs to check to see if it was already logged for the day. If their ip IS there then it will check to see how many messages they've sent today, if it is less than 5 then it will let them send the message and add 1 to the log. Otherwise it won't let them send the message.

 

 

Tell me if it sounds too complicated.

Link to comment
Share on other sites

Sorry about the late reply, since I couldn't get it to work I didn't feel the need to save the code, but this is basically what I used last

<?php
$username="imakeang_angry";
$password="tpark701234";
$database="imakeang_records";

mysql_connect(localhost,$username,$password);
mysql_select_db($database);


$ip = $_SERVER['REMOTE_ADDR'];


$query="SELECT * FROM ip WHERE address='$ip'" or die(mysql_error());
$result=mysql_query($query) or die("mysql_error() 1");


$ip_rec_address=mysql_result($result,$i,"address");
$ip_rec_sent=mysql_result($result,$i,"sent");


if ( $ip_rec_address == $ip ) {
if ( $ip_rec_sent == 2 ) {
	echo "You have sent too many messages today, wait until tomorrow to send another.";
}


else {
$query = "INSERT INTO global_sent VALUES ('$result + 1')";
mysql_query($query);
echo "$result messages sent.";
}
}
mysql_close();

?>

 

This returns "Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5" on line 27 and 18.

 

 

The Little Guy - I'll try that out right now.

Link to comment
Share on other sites

Did you honestly just put your DB username and PW here!?

 

Have you tried running the SQL quiry through say phpmyadmin? You might have an error (like a wrong field name?)

 

Also try adding `` round your field names in the quiry, and remove the '' around $ip

 

just a few ideas that probably won't solve the problem!

 

Good luck

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.