mervyndk Posted May 16, 2008 Share Posted May 16, 2008 I'm trying to create a login form for my website. It needs to have any user enter a set password as well as their own name and e-mail address (they will not have to register). Their name and e-mail address will be sent to my e-mail address, while the password is used for simple guest authentication (I only want people I have told about the website to be able to get it - fingers crossed!). I've had no problem in creating the name/e-mail form and php script, but don't know how to get the password included. Here's the script I'm using for the name/e-mail. Ideally, the password would be protecting access to all pages in the site. Any help would be greatly appreciated. <? // ------------- CONFIGURABLE SECTION ------------------------ // $mailto - set to the email address you want the form // sent to, eg //$mailto = "[email protected]" ; $mailto = '[email protected]' ; // $subject - set to the Subject line of the email, eg //$subject = "Feedback Form" ; $subject = "Your Website has had a visitor" ; // the pages to be displayed, eg //$formurl = "http://www.example.com/feedback.html" ; //$errorurl = "http://www.example.com/error.html" ; //$thankyouurl = "http://www.example.com/thankyou.html" ; $formurl = "http://www.mysite.com/index.htm" ; $errorurl = "http://www.mysite.com/error.htm" ; $thankyouurl = "http://www.mysite.com/firstpage.htm" ; // -------------------- END OF CONFIGURABLE SECTION --------------- //$name = $_POST['name'] ; //$email = $_POST['email'] ; //$comments = $_POST['comments'] ; $email=htmlentities($_POST['email']); $fname=urldecode($_POST['fname']); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (empty($fname) || empty($email)) { header( "Location: $errorurl" ); exit ; } $name = strtok( $name, "\r\n" ); $email = strtok( $email, "\r\n" ); if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } //List of Headers $headers.="Content-type: text/html; charset=iso-8859-1\r\n"; $headers.="From: $email\r\nReply-To: $email"; header( "Location: $thankyouurl" ); $messageproper = " First Name: $fname <br> E-mail Address: $email <br> . "; //mail() function sends the mail mail($mailto,$subject,$messageproper,$headers) ?> Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/ Share on other sites More sharing options...
jonsjava Posted May 16, 2008 Share Posted May 16, 2008 <?php $password = "somepassword"; if ($_POST['password'] == $password){ // ------------- CONFIGURABLE SECTION ------------------------ // $mailto - set to the email address you want the form // sent to, eg //$mailto = "[email protected]" ; $mailto = '[email protected]' ; // $subject - set to the Subject line of the email, eg //$subject = "Feedback Form" ; $subject = "Your Website has had a visitor" ; // the pages to be displayed, eg //$formurl = "http://www.example.com/feedback.html" ; //$errorurl = "http://www.example.com/error.html" ; //$thankyouurl = "http://www.example.com/thankyou.html" ; $formurl = "http://www.mysite.com/index.htm" ; $errorurl = "http://www.mysite.com/error.htm" ; $thankyouurl = "http://www.mysite.com/firstpage.htm" ; // -------------------- END OF CONFIGURABLE SECTION --------------- //$name = $_POST['name'] ; //$email = $_POST['email'] ; //$comments = $_POST['comments'] ; $email=htmlentities($_POST['email']); $fname=urldecode($_POST['fname']); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (empty($fname) || empty($email)) { header( "Location: $errorurl" ); exit ; } $name = strtok( $name, "\r\n" ); $email = strtok( $email, "\r\n" ); if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } //List of Headers $headers.="Content-type: text/html; charset=iso-8859-1\r\n"; $headers.="From: $email\r\nReply-To: $email"; header( "Location: $thankyouurl" ); $messageproper = " First Name: $fname E-mail Address: $email . "; //mail() function sends the mail mail($mailto,$subject,$messageproper,$headers) } else{ //do something } ?> Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542894 Share on other sites More sharing options...
mervyndk Posted May 16, 2008 Author Share Posted May 16, 2008 That doesn't seem to work. Just gives me a Parse error: syntax error, unexpected '}' coming just before the ?>. My form action calls this PHP script by posting. Don't know if that is affecting this in any way. Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542912 Share on other sites More sharing options...
jonsjava Posted May 16, 2008 Share Posted May 16, 2008 oops. overlooked something. here <?php $password = "somepassword"; if ($_POST['password'] == $password){ // ------------- CONFIGURABLE SECTION ------------------------ // $mailto - set to the email address you want the form // sent to, eg //$mailto = "[email protected]" ; $mailto = '[email protected]' ; // $subject - set to the Subject line of the email, eg //$subject = "Feedback Form" ; $subject = "Your Website has had a visitor" ; // the pages to be displayed, eg //$formurl = "http://www.example.com/feedback.html" ; //$errorurl = "http://www.example.com/error.html" ; //$thankyouurl = "http://www.example.com/thankyou.html" ; $formurl = "http://www.mysite.com/index.htm" ; $errorurl = "http://www.mysite.com/error.htm" ; $thankyouurl = "http://www.mysite.com/firstpage.htm" ; // -------------------- END OF CONFIGURABLE SECTION --------------- //$name = $_POST['name'] ; //$email = $_POST['email'] ; //$comments = $_POST['comments'] ; $email=htmlentities($_POST['email']); $fname=urldecode($_POST['fname']); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (empty($fname) || empty($email)) { header( "Location: $errorurl" ); exit ; } $name = strtok( $name, "\r\n" ); $email = strtok( $email, "\r\n" ); if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } //List of Headers $headers.="Content-type: text/html; charset=iso-8859-1\r\n"; $headers.="From: $email\r\nReply-To: $email"; header( "Location: $thankyouurl" ); $messageproper = " First Name: $fname E-mail Address: $email . "; //mail() function sends the mail mail($mailto,$subject,$messageproper,$headers); } else{ //do something } ?> Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542913 Share on other sites More sharing options...
mervyndk Posted May 16, 2008 Author Share Posted May 16, 2008 Thanks for your help! Don't know what you changed (or overlooked) but it seems to be working. Now, when I enter a wrong password, it just goes to a blank page. Is there a way to make it go to the error page? Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542927 Share on other sites More sharing options...
jonsjava Posted May 16, 2008 Share Posted May 16, 2008 where it says else{ //do something } change "do something" by doing something Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542928 Share on other sites More sharing options...
mervyndk Posted May 16, 2008 Author Share Posted May 16, 2008 Duh! Sorry about that - as a newbie my brain is not firing on all cylinders. It works fine now. Thanks again for your help. Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542931 Share on other sites More sharing options...
947740 Posted May 16, 2008 Share Posted May 16, 2008 Please hit the "Topic Solved" button in the lower left-hand corner of the page. Link to comment https://forums.phpfreaks.com/topic/105939-login-form-question/#findComment-542949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.