Jump to content

login script


werny

Recommended Posts

this is from a tutorial I read, I am trying to tweak some of the settings to suit my needs, out of this register script I am trying to take out the whole send an email, with a random number, and I am trying to add in another value, here the script

<?php
require_once('db.php');
include('functions.php');
include('settings.php');

if (array_key_exists('_submit_check', $_POST))
{
	if ( $_POST['username'] != '' && $_POST['password'] != '' && $_POST['password'] == $_POST['password_confirmed'] && $_POST['email'] != '' && valid_email ( $_POST['email'] ) == TRUE )
	{
		if ( ! checkUnique('Username', $_POST['username']) )
		{
			$error = 'Username already taken. Please try again!';
		}
		elseif ( ! checkUnique('Email', $_POST['email']) )
		{
			$error = 'The email you used is associated with another user. Please try again or use the "forgot password" feature!';
		}
		else {		
			$query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());

			$getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error());

			if(mysql_num_rows($getUser)==1)
			{			
				$row = mysql_fetch_assoc($getUser);
				$headers = 	'From: ' . $site_email . "\r\n" .
	    					'Reply-To: ' . $site_email . "\r\n" .
	    					'X-Mailer: PHP/' . phpversion();
				$subject = "Activation email from " . $domain_name;
				$message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: ".$url."confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining";
				if ( mail($row['Email'], $subject, $message, $headers ) )
				{
					$msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
				}
				else {
					$error = 'I created the account but failed sending the validation email out.';
				}
			}
			else {
				$error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.';
			}
		}							
	}
	else {		
		$error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match one another';	
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>register</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div id="log">
<?php	if ( isset ( $error ) )	{ echo '			<p class="error">' . $error . '</p>' . "\n";	}	?>
<?php	if ( isset ( $msg ) )	{ echo '			<p class="msg">' . $msg . '</p>' . "\n";	} else {//if we have a mesage we don't need this form again.?>
</div>

<div id="container" style="text-align:center">
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

	<input type="hidden" name="_submit_check" value="1"/> 

	<table align="center" width="99%">

		<tr>
			<td><div align="left">Username</div></td>
		</tr>
		<tr>
			<td><div align="left"><input class="input" type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /></div></td>				
		</tr>
		<tr>

			<td><div align="left">Password</div></td>
		</tr>
		<tr>				
			<td><div align="left"><input class="input" type="password" id="password" name="password" size="32" value="" /></div></td>				
		</tr>
		<tr>

			<td><div align="left">Re-Password</div></td>
		</tr>
		<tr>				
			<td><div align="left"><input class="input" type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /></div></td>				
		</tr>
		<tr>
			<td><div align="left">Email</div></td>
		</tr>
		<tr>			
			<td><div align="left"><input class="input" type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /></div></td>

		</tr>

		<tr>
			<td>
			<input type="image" name="register" value="register"  class="submit-btn" src="images/btn.gif" alt="submit" title="submit" />
			<br class="clear" />
			</td>
		</tr>

	</table>
</form>
</div>
<? } ?>
</body>

</html>

basically I am terrible about how to take out pieces of it, such as switching the random key to inserting into a field called nation_name, and taking out the whole send an email with random key

Link to comment
Share on other sites

Well, obviously this chunk of code is what sends the email:

 

<?php

				$headers = 	'From: ' . $site_email . "\r\n" .
	    					'Reply-To: ' . $site_email . "\r\n" .
	    					'X-Mailer: PHP/' . phpversion();
				$subject = "Activation email from " . $domain_name;
				$message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: ".$url."confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining";
				if ( mail($row['Email'], $subject, $message, $headers ) )
				{
					$msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
				}
				else {
					$error = 'I created the account but failed sending the validation email out.';
				}

?>

 

And this is the query inserting info into the DB.

 

<?php

$query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());

?>

Link to comment
Share on other sites

I'll show you dirty code.

 

$let = "them be";

function backOff($user){
global $let;
echo "Let " . $let . " " . $user;
}

$peer = "TheFilmGod";
backOff($peer);

 

Atleast they're trying to tweak it, don't tell them they're not learning. Most people started off on tutorials and got where they are now.

Link to comment
Share on other sites

I'll show you dirty code.

 

$let = "them be";

function backOff($user){
global $let;
echo "Let " . $let . " " . $user;
}

$peer = "TheFilmGod";
backOff($peer);

 

Atleast they're trying to tweak it, don't tell them they're not learning. Most people started off on tutorials and got where they are now.

thanks man ill try that out, and yeah saying there is no classes or any formal way to learn, I have to learn from tutorials and such

Link to comment
Share on other sites

I'll show you dirty code.

 

$let = "them be";

function backOff($user){
global $let;
echo "Let " . $let . " " . $user;
}

$peer = "TheFilmGod";
backOff($peer);

 

Atleast they're trying to tweak it, don't tell them they're not learning. Most people started off on tutorials and got where they are now.

 

Sure copying and pasting is learning? Is it really learning? Grab a good book and digest the fundamentals of php. If you choose to be cheap, you'll get cheap code right back. Of course you can argue, but copying and pasting is not "learning?"

Link to comment
Share on other sites

I'll show you dirty code.

 

$let = "them be";

function backOff($user){
global $let;
echo "Let " . $let . " " . $user;
}

$peer = "TheFilmGod";
backOff($peer);

 

Atleast they're trying to tweak it, don't tell them they're not learning. Most people started off on tutorials and got where they are now.

 

Very true, I did, and though I know I still have a lot of learning to do, at least I can code my own game now

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.

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.