Jump to content

Limit 2 Accounts/Users per ip


dashcrash

Recommended Posts

Hello all,

I am a total noob in php and some VIP asked me to make something simple for our clubhouse;

A page where users can submit/input 2 codes through a textbox and store it in a database.

 

There are 2 things i want: max 2 submits/inputs per IP(to prevent abuse)(ip stored in database).

$ip = $_SERVER['REMOTE_ADDR'];
$check = mysql_query("select * from table where ipcolumn='$ip'");
if (mysql_num_rows($check) > 0)
$insertip = "insert into table (ipcolumn) values ('$ip')";

 

And i wanna catch the error when an user put in a code lower than 5 characters.

not something like:

if ($textarea == ""){

 

This is where i am so far.

 

new.php

<?php
include 'includes/config.php';

mysql_select_db($mysql_database, $con);
$sql="INSERT INTO users (code, code2)
VALUES

('$_POST[code]','$_POST[code2]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
}else{

    header ("Location: /thanks.php");
}


?>

 

includes/config.php

<?php

$mysql_host = "myhost.com";
$mysql_database = "mydb";
$mysql_user = "myuser";
$mysql_password = "mypass";

$con = mysql_connect($mysql_host,$mysql_user,$mysql_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
?>

 

sql.sql

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `code` varchar(30) collate latin1_general_ci NOT NULL,
  `code2` varchar(32) collate latin1_general_ci default NULL,
  `timestamp` int(11) unsigned NOT NULL,
  PRIMARY KEY  (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

 

index.html

<form action="new.php" method="post"
onsubmit="return onSubmitButton();"> 
        <input value="" id="something" class="LoginForm-Input" name="code1" size="34" style="float: left;">

[/code]

Link to comment
Share on other sites

edit: i cannot add the 2(lets say) modules(max user per ip and min. 5 charactars per textbox), it either gives me an error or somethign else happens.

So i seperated the workign and not wkring code and posted it above so maybe some1 else can fix it.

 

2ns edit:I m sorry but English isnt my first language, so if i need to explain something, just tell me.

Link to comment
Share on other sites

Ok i tried some stuff but i cant get it fixed  :confused:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /public_html/new.php on line 8

 

Error: Duplicate entry '' for key 1

 

<?php
include 'includes/config.php';

//check for ip
$ip = $_SERVER['REMOTE_ADDR'];
$check = mysql_query("select * from users where IP='$ip'");

if (mysql_num_rows($check) > 0)
{
echo "Sorry you have already submitted a code from this IP";
}
else
{
//carry on processing

$insertip = "insert into table (IP) values ('$ip')";
mysql_query($insertip);

//carry on processing
}  

// Code to short Error Message
$ErrorMsg = "Code needs to be longer than 5";
// Set minium code length
$minpass = 5;

// If code is less than $minpass, created error message
if($_POST['code'] < $minpass) {
$ErrorMsg .= "Code needs to be longer than 5";
}

mysql_select_db($mysql_database, $con);


$sql="INSERT INTO users (code, code2)

VALUES

('$_POST[code]','$_POST[code2]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());

}else{

    header ("Location: /thanks.php");

}


?>

 

New sql:

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `code` varchar(30) collate latin1_general_ci NOT NULL,
  `code2` varchar(32) collate latin1_general_ci default NULL,
  `IP` varchar(25) collate latin1_general_ci NOT NULL default '',
  `timestamp` int(11) unsigned NOT NULL,
  PRIMARY KEY  (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

[/code]

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.