ChompGator Posted December 2, 2007 Share Posted December 2, 2007 Boy do I have lots of PHP Questions today, Im only posting one at a time though so I have time to write my scripts and understand them. I was wondering if someone could help me out, or point me to a tutorial online, what I did was make a 'join this website' link, and Ive already made the form - and what I want to happen is when the user clicks the submit button, the server sends them an email with a link to validate their account once they click the link, they have been added to the "Master Member List" I already have the form, and the handleform.php (the script that handles the form.htm) entering their data into the database, but only once they click the validation link that is sent to them, they are added to the master list. Does anyone know a script for a validation link that I can add to my script? Thank Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/ Share on other sites More sharing options...
scarlson Posted December 2, 2007 Share Posted December 2, 2007 I had the same problem before and I found a script in a book I had. Here is my code with the email verification in it. You need to setup your database for the login table to have a field to set if active or not. <?php session_start(); include 'dbconnect.php'; if($_POST['Submit']) { $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM login WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:ad_setup.php"); } else { echo "<div id='error_setup'>The account information does not exist, Try again!</div>"; } ob_end_flush(); } if($_POST['create']) { if($_POST['password1'] == $_POST['password2']) { $checksql = "SELECT * FROM login WHERE username = '" . $_POST['username'] . "';"; $checkresult = mysql_query($checksql); $checknumrows = mysql_num_rows($checkresult); if($checknumrows == 1) { header("Location: http://www.garagesalelister.com/account_setup.php?error=taken"); } else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://www.garagesalelister.com/verify.php"; $verifystring = urlencode($randomstring); $verifyemail = urlencode($_POST['email']); $validusername = $_POST['username']; $sql = "INSERT INTO login(username, password, email, verifystring, active) VALUES('" . $_POST['username'] . "', '" . $_POST['password1'] . "', '" . $_POST['email'] . "', '" . addslashes($randomstring) . "', 0);"; mysql_query($sql); $mail_body=<<<_MAIL_ Hi $validusername, Thank you for registering with Garage Sale Lister. Please click on the following link to verify your new account: $verifyurl?email=$verifyemail&verify=$verifystring _MAIL_; mail($_POST['email'], "Garage Sale Lister User Verification", $mail_body); echo "A link has been emailed to the address you entered below. Please follow the link in the email to validate your account and to start posting your Garage Sale Items now."; } } else { header("Location: http://www.garagesalelister.com/account_setup.php?error=pass"); } } else { switch($_GET['error']) { case "pass": echo "<div id='error_setup'>Passwords do not match!</div>"; break; case "taken": echo "<div id='error_setup'>Username taken, please use another.</div>"; break; case "no": echo "<div id='error_setup'>Incorrect login details!</div>"; break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404352 Share on other sites More sharing options...
ChompGator Posted December 2, 2007 Author Share Posted December 2, 2007 Thankyou Muchly, Ill give it a shot - thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404355 Share on other sites More sharing options...
ChompGator Posted December 2, 2007 Author Share Posted December 2, 2007 One thing, I noticed you have a header pointing to a url location, - what do you have stored there, I should be able to remove that huh? Anyway let me know Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404367 Share on other sites More sharing options...
scarlson Posted December 2, 2007 Share Posted December 2, 2007 You should be able to take out all those headers, basically they are just used to refresh the screen when an error is passed and it's then displayed. Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404369 Share on other sites More sharing options...
ChompGator Posted December 3, 2007 Author Share Posted December 3, 2007 Question about the validation script again, Im testing it out on my server now and Im getting an error saying "PHP Has Encountered a Stack Over-Flow" What does this mean? And what are some suggestions to fix it, Ill also look up and asses the problem, - thanks, Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404555 Share on other sites More sharing options...
ChompGator Posted December 3, 2007 Author Share Posted December 3, 2007 Ok, before I add my big form, Im just trying to do a test form just with 3 simple fields, "username" "password" "email" So below is new.htm and then the php document that is supposed to handle the form is new.htm, the name of the php document is "email.php Im submitting the form and its just taking me to a page cannot be displayed - I do have a dbconnect.php (that is stated at the start of the php document.) - What do you see wrong with this code that I can fix? new.htm <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form name="input" action="email.php" method="post"> Username: <input type="text" name="user"><br /> Password: <input type="text" name="user0"><br /> Email <input type="text" name="user1"><br /> <br /> <input type="submit" value="Submit"> </form> </body> </html> email.php <?php session_start(); include 'dbconnect.php'; if($_POST['Submit']) { $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM join WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:ad_setup.php"); } else { echo "<div id='error_setup'>The account information does not exist, Try again!</div>"; } ob_end_flush(); } if($_POST['create']) { if($_POST['password1'] == $_POST['password2']) { $checksql = "SELECT * FROM join WHERE username = '" . $_POST['username'] . "';"; $checkresult = mysql_query($checksql); $checknumrows = mysql_num_rows($checkresult); } else { for($i = 0; $i < 16; $i++) { $randomstring .= chr(mt_rand(32,126)); } $verifyurl = "http://www.jetbluevirtual.net/join/verify.php"; $verifystring = urlencode($randomstring); $verifyemail = urlencode($_POST['email']); $validusername = $_POST['username']; $sql = "INSERT INTO join(username, password, email, verifystring, active) VALUES('" . $_POST['username'] . "', '" . $_POST['password1'] . "', '" . $_POST['email'] . "', '" . addslashes($randomstring) . "', 0);"; mysql_query($sql); $mail_body=<<<_MAIL_ Hi $validusername, Welcome To JBU Please click on the following link to verify your new account: $verifyurl?email=$verifyemail&verify=$verifystring _MAIL_; mail($_POST['email'], "JBU", $mail_body); echo "A link has been emailed to the address you entered. Please see the email - to activate your account"; } } else { switch($_GET['error']) { case "pass": echo "<div id='error_setup'>Passwords do not match!</div>"; break; case "taken": echo "<div id='error_setup'>Username taken, please use another.</div>"; break; case "no": echo "<div id='error_setup'>Incorrect login details!</div>"; break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404561 Share on other sites More sharing options...
scarlson Posted December 3, 2007 Share Posted December 3, 2007 header("location:ad_setup.php"); This was the name of my .php page to return the errors to. You will need to put your .php file name there. Quote Link to comment https://forums.phpfreaks.com/topic/79856-validation/#findComment-404646 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.