Jump to content

Recommended Posts

Would someone mind if I posted the code for a single file, I doubt it's more than a hundred lines. Then someone could maybe look at it?

 

Basically I'm knew to the whole PHP thing and I just want to see if I'm going in the right direction 'cause I'm finally trying to make something from scratch.

 

I won't get into the habit of doing this with every file I ever make don't worry. :P

Link to comment
https://forums.phpfreaks.com/topic/64824-quick-question/
Share on other sites

Don't worry I always use code tags MadTechie. :P

 

Ok here goes, thanks a lot.

<?php

/*--------------------------*\
@File: register.php
@Author: Joe
@Created: 11/August/07 5:54 AM
@Modified: 13/August/07 12:00 PM
@Revision: 2
\*--------------------------*/

if(isset($_POST['submit'])) {

  $a = "":
  $b = "";
  $c = "";
  $d = "";

include ("connect.php");

$connect = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ();
mysql_select_db (DB_NAME) OR die();

  if (empty($_POST['mem_name'])) {
  die('You didn\'t enter a Username.'); }
  else {
  $a = mysql_real_escape_string($_POST['mem_name']); }


  $query = mysql_query("SELECT * FROM `gs_mem` WHERE `mem_name` = '".$a."'");
  $fetch = mysql_fetch_object($query);
   
  if($fetch->mem_name == $a) {
  die('The Username you chose is already taken.'); }

  md5($a);

  if (empty($_POST['mem_pass'])) {
  die('You didn\'t enter a Password.'); }
  else {
  $b = mysql_real_escape_string($_POST['mem_pass']); }


  if (empty($_POST['mem_vpass'])) {
  die('You didn\'t verify your Password.'); }
  else {
  $c = mysql_real_escape_string($_POST['mem_vpass']); }


  if($b != $c) { 
  die('The Passwords you entered do not match.'); }


  if(strlen($b) < 8 ) {
  die('Your Password must consist of at least 8 characters.'); }

  md5($b);

  if (empty($_POST['mem_email'])) {
  die('You didn\'t enter an Email Address.'); }
  else {

  $d = mysql_real_escape_string($_POST['mem_email']); }

  $e = md5(uniqid(rand(),1));

if ($a && $b && $d) {

  $insert = "INSERT INTO `gs_mem` (mem_name, mem_pass, mem_email, mem_active, mem_validate) VALUES ('".$a."', 

'".$b."', '".$d."', '0', '".$e."')";

  $insert = mysql_query($insert);
  if(!$insert) die(mysql_error());

  $getvalcode = "SELECT mem_validate FROM gs_mem ORDER BY mem_id DESC LIMIT  1";
  $result = mysql_query($getvalcode) or die(mysql_error());
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  $valcode = $row['mem_validate']; }

  $to = $d;
  $subject = "GameSpaces - Validation Code";
  $body = "You need to activate your GameSpaces account, to do so please copy the following code and enter it on the page you were taken to after registering. Your code: $valcode";

  mail($to, $subject, $body, $from_header);

  echo('Your Account has been created.'); } }

  else {

  echo('You may not access this file directly.'); }

?>

Link to comment
https://forums.phpfreaks.com/topic/64824-quick-question/#findComment-323403
Share on other sites

OK MD5 + salt we talked about

 

Use of $a $b $c, will cause you problems later use names like $mName it save scrolling up look for what the $a was set to..

 

the code itself looks ok

 

 

maybe a few changes

 

$insertSQL = "INSERT INTO `gs_mem` (mem_name, mem_pass, mem_email, mem_active, mem_validate) VALUES ('".$a."', 

'".$b."', '".$d."', '0', '".$e."')";

  $insert = mysql_query($insertSQL);
mysql_query($insertSQL);
$uID = mysql_insert_id();

  if(!$insert) die(mysql_error());

  $getvalcode = "SELECT mem_validate FROM gs_mem WHERE mem_id = $uID";

 

 

Link to comment
https://forums.phpfreaks.com/topic/64824-quick-question/#findComment-323409
Share on other sites

I have an id row in the database and it is set to auto increment so do I not need to do what you said?

 

Wait I see what you did now...it's to make sure if two people register at the same time they don't get the wrong validation code right? Like the insert id will always be same as the mem_id that is set to auto increment so there is no chance of them getting the wrong code?

Link to comment
https://forums.phpfreaks.com/topic/64824-quick-question/#findComment-323418
Share on other sites

correct

quick update

 

comments and where

  $insert = mysql_query($insertSQL);
$uID = mysql_insert_id(); //<--gets the auto increment

  if(!$insert) die(mysql_error());

  $getvalcode = "SELECT mem_validate FROM gs_mem WHERE id = $uID";//Finds the user

Link to comment
https://forums.phpfreaks.com/topic/64824-quick-question/#findComment-323421
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.