Jump to content

Only one instance of an IP can register.


Recommended Posts

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>');
		echo '';


I think the problem is with the mySQL query...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

I have a Text Captcha class I wrote! Very easy to use!


The class:

    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
    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;
				$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>'.
				$this->xml = new SimpleXMLElement($fallback);
			$this->question = $_SESSION['~TC'];
	function question(){
		return $this->question;
	function refresh($title = "Refresh"){
			header("Location: ".$this->getURL(false));
			return '<a href="'.$this->getURL(true).'newQuestion">'.$title.'</a>';
	function correctAnswer($ans){
		$ra = $_POST[$this->postVar];
		$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'];
			$page .= "&";
			$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);
			return md5($ans.$this->salt);


An Example:


//To gain an API key, visit: http://textcaptcha.com/register
$TextCaptcha = new TextCaptcha("MY API KEY HERE");

		echo "Correct, ";
		echo "No, ";
	echo '<a href="?">Try Again!</a>';

	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 :/

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.

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.