GiacJr Posted November 13, 2010 Share Posted November 13, 2010 I'm trying to make my register script check the database's IP column and compare it with the user's IP. If the User's IP equals that in the DB column, it should say "Sorry, there is already an account registered with your IP Address. Please log in.", and if there's no IP match, it should allow them to continue with registering. I've been tinkering around with this for a while and I can't seem to figure it out. Any help would be appreciated if ($_SERVER['REMOTE_ADDR'] == mysql_query("SELECT ip FROM users")) { die('Sorry, there is already an account registered with your IP Address. Please <a href="/login.php>log in.</a>'); }else{ echo ''; } I think the problem is with the mySQL query... Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/ Share on other sites More sharing options...
Pikachu2000 Posted November 13, 2010 Share Posted November 13, 2010 Then what happens when the user's IP address changes and it gets assigned to someone else that wants to sign up? What about a large company that uses a proxy server and all requests appear to be from the same IP address? Overall, trying to do it the way you describe is not a great idea. Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1133707 Share on other sites More sharing options...
GiacJr Posted November 13, 2010 Author Share Posted November 13, 2010 It's only for a small website and to prevent people from using scripts to register hundreds of accounts. If it gets bigger, we'll find better ways to ensure we're not exploited, but for now, this is the best option. Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1133709 Share on other sites More sharing options...
requinix Posted November 13, 2010 Share Posted November 13, 2010 If it gets bigger, we'll find better ways to ensure we're not exploited, but for now, this is the best option. Have you considered captchas? Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1133731 Share on other sites More sharing options...
GiacJr Posted November 13, 2010 Author Share Posted November 13, 2010 Yes, and as I said, once we get bigger, we will be looking at better ways, but for now I'd like to just get this script working. Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1133768 Share on other sites More sharing options...
BlueSkyIS Posted November 13, 2010 Share Posted November 13, 2010 here is some info on how to properly use mysql_query(): http://www.freewebmasterhelp.com/tutorials/phpmysql/4 Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1133791 Share on other sites More sharing options...
GiacJr Posted November 17, 2010 Author Share Posted November 17, 2010 Yeah...didn't really help. Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1135355 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Share Posted November 17, 2010 I have a Text Captcha class I wrote! Very easy to use! The class: <?php /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ //Created By James Little class TextCaptcha{ private $question; private $xml; private $postVar = "realAns"; private $salt = "Something Really Really Random, like 79"; function __construct($api, $url = "http://textcaptcha.com/api/"){ @session_start(); //Starts session if one has not already been started. @ messages any errors it may produce. if(!isset($_SESSION['~TC'])){ //So if called on page, does not send request more than once. //Grab question and answers! $url = $url.$api; try{ $this->xml = @new SimpleXMLElement($url, NULL, true); }catch(Exception $e){ //Could not Connect, this is the default $fallback = '<captcha>'. '<question>How many wheels does a car have?</question>'. '<answer>'.md5(4).'</answer> <answer>'.md5("four").'</answer></captcha>'; $this->xml = new SimpleXMLElement($fallback); } $this->setQA(); }else $this->question = $_SESSION['~TC']; } function question(){ return $this->question; } function refresh($title = "Refresh"){ if(isset($_GET['newQuestion'])){ unset($_SESSION['~TC']); header("Location: ".$this->getURL(false)); }else return '<a href="'.$this->getURL(true).'newQuestion">'.$title.'</a>'; } function correctAnswer($ans){ $ra = $_POST[$this->postVar]; unset($_SESSION['~TC']); $ans = $this->setAns($ans); for($i = 0; $i<count($ra); $i++){ if($ra[$i] === $ans){ return true; } } return false; } private function setQA(){ //Set the questions and answers. $this->question = (string) $this->xml->question; $addOn = ""; foreach ($this->xml->answer as $hash){ $addOn .= '<input type="hidden" name="'.$this->postVar.'[]" value="'.$this->setAns((string) $hash, false).'" />'; } $this->question = $addOn.$this->question; $_SESSION['~TC'] = $this->question; } private function getURL($fix){//This Function needs to be rewritten. $page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; $page .= "?"; if(count($_SERVER['QUERY_STRING']) > 0) $page .= $_SERVER['QUERY_STRING']; if($fix) $page .= "&"; else $page = str_replace("&newQuestion", "", $page); return $page; } private function setAns($ans, $userInput = true){ if($userInput) //Because the answers already come in as hashed, but they need to be reshash with salt return md5(md5(strtolower(trim($ans))).$this->salt); else return md5($ans.$this->salt); } }; ?> An Example: <?php //To gain an API key, visit: http://textcaptcha.com/register include("TextCaptcha.php"); $TextCaptcha = new TextCaptcha("MY API KEY HERE"); if(isset($_POST['submit'])){ if($TextCaptcha->correctAnswer($_POST['answer'])) echo "Correct, "; else echo "No, "; echo '<a href="?">Try Again!</a>'; unset($_POST['submit']); }else{ echo '<form action="?" method="post" name="TC">'; echo $TextCaptcha->question(); echo " "; echo $TextCaptcha->refresh("New Question"); echo '<br />'; echo '<input type="input" name="answer" />'; echo '<input type="submit" name="submit" value="Submit" />'; echo '</form>'; } ?> Also read that article posted, I know it will help you. Take the time to read. We do not post answers, but the path to the answers. Quit being lazy :/ Quote Link to comment https://forums.phpfreaks.com/topic/218541-only-one-instance-of-an-ip-can-register/#findComment-1135361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.