werny Posted September 13, 2007 Share Posted September 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/ Share on other sites More sharing options...
pocobueno1388 Posted September 13, 2007 Share Posted September 13, 2007 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347433 Share on other sites More sharing options...
werny Posted September 13, 2007 Author Share Posted September 13, 2007 I found that but when I just try to clean cut out the emailing it gives errors, and when I am trying to switch from the rand function to the string escape function I get errors, I think I just edit one thing wrong Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347440 Share on other sites More sharing options...
TheFilmGod Posted September 13, 2007 Share Posted September 13, 2007 Don't waste your time copying and pasting code. You aren't learning. You won't ever make any good sites until you make your own code. That code is also bullcrap. Seriously, the way it's set up is "dirty code." Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347486 Share on other sites More sharing options...
marcus Posted September 13, 2007 Share Posted September 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347491 Share on other sites More sharing options...
werny Posted September 13, 2007 Author Share Posted September 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347697 Share on other sites More sharing options...
TheFilmGod Posted September 13, 2007 Share Posted September 13, 2007 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?" Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347871 Share on other sites More sharing options...
darkfreaks Posted September 13, 2007 Share Posted September 13, 2007 I agree with film god copying other Peoples code is not learning it is stealing. if you want to Learn PHP yourself i suggest you go look into "Spring into PHP 5" its like $20 on amazon. Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347883 Share on other sites More sharing options...
almightyegg Posted September 13, 2007 Share Posted September 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347886 Share on other sites More sharing options...
darkfreaks Posted September 13, 2007 Share Posted September 13, 2007 yeah as long as you learn how to code from it. this other guy who started this topic appearantly keeps asking how to solve all his problems even if they are obvious and simple to fix. he should go get some PHP books and honestly study how to code. Quote Link to comment https://forums.phpfreaks.com/topic/69120-login-script/#findComment-347889 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.