Hi,
I hope you can answer this question.
Is it possible to make a form with ip check? I want people to vote on their favorite person/thing/whatever, but every ip may only fill in the form once.
I found this already on the forum but can you give me some more info about which PHP+MySQL code I need to use?
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=16&t=93383
Regards,
Smedia
I hope you can answer this question.
Is it possible to make a form with ip check? I want people to vote on their favorite person/thing/whatever, but every ip may only fill in the form once.
I found this already on the forum but can you give me some more info about which PHP+MySQL code I need to use?
http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=16&t=93383
Regards,
Smedia
Hi Smedia,
I think that this FAQ has the basic code you need except that (a) you'd need to add a database query to see if the address has already been used and (b) you'd need to show a polite message if it has.
Bob
PS In some parts of the world shared IP addresses are common, and in others they can change frequently (like mine does).
I think that this FAQ has the basic code you need except that (a) you'd need to add a database query to see if the address has already been used and (b) you'd need to show a polite message if it has.
Bob
PS In some parts of the world shared IP addresses are common, and in others they can change frequently (like mine does).
Hi Bob,
Thnx for the quick reply!
That looks like it. Im not realy a php script wizzard so I have to check if it works :wink:
I think this code solves a part of my problem. But its not an option to manualy add all the ip adresses that are already used. We will be expecting many voters. Is there a way automate this proces via database check or some ohter way?
Smedia
Thnx for the quick reply!
That looks like it. Im not realy a php script wizzard so I have to check if it works :wink:
I think this code solves a part of my problem. But its not an option to manualy add all the ip adresses that are already used. We will be expecting many voters. Is there a way automate this proces via database check or some ohter way?
Smedia
Hi Smedia,
Yes, you'll need to add a DB query (or a DB Multi Record Loader action) to get a list of saved IP addresses to check against.
Bob
Yes, you'll need to add a DB query (or a DB Multi Record Loader action) to get a list of saved IP addresses to check against.
Bob
Hi Bob,
Ive been trying and trying, but I cant get it to work. Everytime I test the php code it gives a
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in... on line 11
Can you help me out?
Im using this php code in the custom code area:
Can you explain what is wrong with line 11?
Regards
Smedia
Ive been trying and trying, but I cant get it to work. Everytime I test the php code it gives a
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in... on line 11
Can you help me out?
Im using this php code in the custom code area:
<?php
mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("name database") or die(mysql_error());
$ip = $_SERVER['REMOTE_ADDR'];
# Full Text Attempt
$query = mysql_query("SELECT `cf_ipadress` FROM `tablename` WHERE `cf_ipadress` = '$ip'");
# Wild Card Attempt
$query = mysql_query("SELECT `cf_ipadress` FROM `tablename` WHERE `cf_ipadress` LIKE '%$ip%'");
# Use any one query from the above!
if (mysql_num_rows($query) > 0)
{
header("Location: http://www.accesdenied.com");
die();
}
?>
Can you explain what is wrong with line 11?
Regards
Smedia
Im aware the [ b ][ /b ] part of the code is wrong. Tried to highlite line 11.
Which Chronoforms version do you have ?
Ok, let's change your code:
First a custom code action:
Then a db record loader action with these settings:
Then another custom code action:
Regards,
Max
First a custom code action:
<?php
$form->data["user_ip"] = $_SERVER['REMOTE_ADDR'];
?>
Then a db record loader action with these settings:
Table: your table with data
Request param: user_ip
DB field: cf_ipaddress
Model: USERIP
Then another custom code action:
<?php
if(!empty($form->data["USERIP"])){
//redirect here, you may replace this code with a "custom server side validation" or "dynamic event switcher" with a redirect action
}
Regards,
Max
Hi Max,
Thnx for the help!
I copied all the scripts as you told me to do. But unfortunaltely with no working result.
The form still works the same as without the script.
Because I had a deadline on this form and I couldnt fix it, I decided to filter the data afterwards via the saved data.
It's not the way I wanted to do this, but in the long run the result will de the same.
I still want to solve this problem so I can make these forms work in future projects.
Do you have any other suggestions or changes in the code so it will work?
Regards,
Smedia
Thnx for the help!
I copied all the scripts as you told me to do. But unfortunaltely with no working result.
The form still works the same as without the script.
Because I had a deadline on this form and I couldnt fix it, I decided to filter the data afterwards via the saved data.
It's not the way I wanted to do this, but in the long run the result will de the same.
I still want to solve this problem so I can make these forms work in future projects.
Do you have any other suggestions or changes in the code so it will work?
Regards,
Smedia
Hi Smedia,
You can add a "debugger" action after the "db record loader" and check the generated SQL statement, please post it here to make sure that it works as expected!
Regards,
Max
You can add a "debugger" action after the "db record loader" and check the generated SQL statement, please post it here to make sure that it works as expected!
Regards,
Max
Hi Smedia,
I think that there is a small typo in Max;s code, he used 'user_id' in one block and 'USERID' later on.
I'd do the same thing all in Custom Code:
Bob
I think that there is a small typo in Max;s code, he used 'user_id' in one block and 'USERID' later on.
I'd do the same thing all in Custom Code:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
if ( !$ip ) {
return false; // how are you going to handle this case?
}
$db =& JFactory::getDBO();
$ query = "
SELECT COUNT(`cf_ipadress`)
FROM `tablename`
WHERE `cf_ipadress` = '{$ip}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
$app =& JFactory::getApplication();
$app->redirect( 'http://www.accesdenied.com');
}
?>
Bob
He Bob and Max,
Sorry for the slow reply.
I will try the code, but I dont know exactly when. First I have some other priorities to coop with.
I will post the feedback when I tested it.
Regards,
Smedia
Sorry for the slow reply.
I will try the code, but I dont know exactly when. First I have some other priorities to coop with.
I will post the feedback when I tested it.
Regards,
Smedia
Hello,
Well I finally got the ip block script to work! 🙂
I didnt use your codes, but I composed one myself from different php sql examples on the net.
Here the result I endedup with:
Thnx for the help!
Regards,
Smedia
Well I finally got the ip block script to work! 🙂
I didnt use your codes, but I composed one myself from different php sql examples on the net.
Here the result I endedup with:
<?php
$sql = sprintf("SELECT ipaddress FROM table_name WHERE ipaddress = '%s'",
mysql_real_escape_string($_SERVER['REMOTE_ADDR'])
);
$query = mysql_query($sql);
if(mysql_num_rows($query) > 0) {
$row = mysql_fetch_array($query);
$mainframe->redirect('http://www.yoururl.com');
}
?>
Thnx for the help!
Regards,
Smedia
This topic is locked and no more replies can be posted.