Jump to content

My ajax register!


Recommended Posts

Im having a problem with my popup ajax register, on my login.php i have the html code for the captha is implemented in, once submitted my ajax register checks all the information in a sperate file which is ajax_register.php how ever the captcha does not function properly i also tried adding in method post and get did not work it wont pick up what being typed into the input for the captcha.

This is the html form in the login.php


<form action="ajax_register.php" method="post" id="registerForm">
       <br />
       <table width="100%" cellspacing="1">
       Username<br />
       <input name="username" id="username"  onkeyup="CheckUsername(this.value);" type="text"/><br />

       Password<br />
       <input id="pw1" name="password" onkeyup="CheckPasswords(this.value);PasswordMatch();" type="password" /><br />

       Confirm Password<br />
       <td><input name="cpassword" id="pw2" onkeyup="PasswordMatch();" type="password" /><br />

       Email<br />
       <input id="email" name="email" onkeyup="CheckEmail(this.value);" type="email" /><br />

       Gender<br />
       <select name="gender" id="gender" type="dropdown">
           <option value="Male">Male</option>
           <option value="Female">Female</option>
       </select><br /><br />

       echo "<img src='captcha_verify.php'/><br />
       <input name='code' type='text' />";
       </table><br />
       <div align="center">
<input type="submit" name="submit" value="Done" class="regbutton">
       <br />
       <div id="callback" style="text-align: center;margin: 0 auto;color: black;background: #FFD9C8; border: 1px solid #F0BAA2;padding: 10px;opacity:
       0.7;color:##232D30;width:80%;display: none; ">
       <br />


this is my ajax_register.php

include "config.php";
global $_CONFIG;
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
require "global_func.php";
$settq=$db->query("SELECT * FROM settings");
$extract = explode('&',$_POST['data']);
foreach($extract as $e) {
$data = explode('=',$e);
$form[$data[0]] = urldecode($data[1]);	

$username = ( isset($form['username'])&&preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i", $form['username'])&&((strlen($form['username'])<32)&&(strlen($form['username'])>=3)) )?$form['username']:'';
if($username && $form['password'] && $form['cpassword'] && $form['email'] && $form['gender']) {

if(md5($_POST['code']) != $_SESSION['key']) 
 die("You've failed the captcha test, please try again!");

if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $form['email'])) { 
die("Sorry, this email is invalid <br />".$form['email']);

if($form['promo'] == "Your Promo Code Here") {

$q=$db->query("SELECT * FROM users WHERE username='{$username}' OR login_name='{$username}'");
$q2=$db->query("SELECT * FROM users WHERE email='{$form['email']}'");
if($db->num_rows($q)) {
echo "Username already in use. Choose another.";
} else if($db->num_rows($q2)) {
echo "E-Mail already in use. Choose another.";
} else if($form['password'] != $form['cpassword']) {
echo "The passwords did not match, please try again!";
} else {
$form['ref'] = abs((int) $form['ref']);
$IP = $db->escape($_SERVER['REMOTE_ADDR']);
$q=$db->query("SELECT * FROM users WHERE lastip='$IP' AND userid={$form['ref']}");
if($db->num_rows($q)) {
	die("No creating referral multies. Bad dog.");
if($form['ref']) {
	$q=$db->query("SELECT * FROM users WHERE userid={$form['ref']}");

$db->query("INSERT INTO users (username, login_name, userpass, level, money, crystals, donatordays, user_level, energy, maxenergy, will, maxwill, brave, maxbrave, hp, maxhp, location, gender, signedup, email, bankmoney, lastip, lastip_signup) VALUES( '{$username}', '{$username}', md5('{$form['password']}'), 1, $sm, 0, 0, 1, 12, 12, 100, 100, 5, 5, 100, 100, 1, '{$form['gender']}', unix_timestamp(), '{$form['email']}', -1, '$IP', '$IP')");
$db->query("INSERT INTO userstats VALUES($i, 10, 10, 10, 10, 10)");

if($form['ref']) {
	require "global_func.php";
	$db->query("UPDATE users SET crystals=crystals+5 WHERE userid={$form['ref']}");
	event_add($form['ref'],"For refering $username to the game, you have earned yourself 5 crystals!",$c);
	$db->query("INSERT INTO referals VALUES('', {$form['ref']}, $i, unix_timestamp(),'{$r['lastip']}','$IP')");
echo "Congratulations! You have signed up, enjoy the game.";
} else {
echo 'You must fill in all fields';	


Link to comment
Share on other sites

Im going to take a shot in the dark here but are you setting a $session['key'] and linking it up with your captcha some where? Cause normally what i thought is for a captcha its just a random set of chars that you set up and a user just copies whats in the image and types it in the text box. In a side note i would hate to fill in a 32 char captcha.

So to make sense of this, if your captcha is less that 32 characters in length something is wrong from what im reading and may be infact wrong

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...