lukenichols Posted April 11, 2013 Share Posted April 11, 2013 Hi guys. I am new to PHP and website design and also new to the forums. I am basically trying to teach myself as much as possible about PHP, HTML, SQL & CSS. I am planning to start by building a simple website. I have already designed a very simple log in screen in a .HTML document. Here is the current code for my log in page. <!DOCTYPE html><html> <head> <form action="Loginprocess.php"> <div> Username: <input type="text" name="username" size="20" maxlength="20" /> <br /> Password: <input type="password" name="password" size="20" maxlength="20" /> <br /> <input type="submit"/> <br /> </div> </form> </head> <body> </body></html> So am I correct to think this page will access the loginprocess.php document once the user clicks the submit button? My question is, once the user clicks the submit button, the loginprocess.php document will be accessed which is effectively changing web page is it not? How can I carry the values from the user entry boxes over to the loginprocess.php document (to check if they are valid)? For now, I would simply like my loginprocess.php document to open the Main.html document. (I will code the data validation etc later on). So I basically need to know if I am going down the right route here? And I would also like to know how to open another web page in php code. Thanks guys Luke Home.php Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 11, 2013 Share Posted April 11, 2013 Yes, that code will send the form information to Loginprocess.php. Since no method is specified, the default of GET will be used which will pass the variables in the URL; a bad idea for passwords. I would suggest adding method="POST" to the form tag. In your Loginprocess.php file, the variable $_POST will be populated with the information sent from the form. $_POST['username'] and $_POST['password'] will hold their values respectively. You can use these variables to authenticate the user and then redirect the page based on the result. The best way to do so would be to simply change the "Location" header before any output is done. You can do this using the header() function: header('Location: Main.html'); That would send the user to Main.html. Of course, that isn't very secure since there is no authentication on that file. Instead, using a session to keep track of the current user would be a better solution. Quote Link to comment Share on other sites More sharing options...
Sanjib Sinha Posted April 12, 2013 Share Posted April 12, 2013 As a beginner please try to understand how data passes from one page to other. Get accustomed with super global arrays. Look at the url, how it changes and you will understand how data travels. You need to understand few very important aspects like array. If you can not visualize array, you will never be able to grasp how a 'form data' passes from one page to other. There are good tutorials in phpfreak. Read them. If you stuck, ask in forum. Best of luck. Quote Link to comment Share on other sites More sharing options...
subhomoy Posted April 12, 2013 Share Posted April 12, 2013 (edited) First of all give a "name" to the submit button or else it will not work. after the submit button use this code of php <?php if(isset($_REQUEST['submit'])){ $uname = $_REQUEST['username']; $pwd = $_REQUEST['password']; header(Location: loginptocess.php?uname=$uname&pwd=$pwd); ?> In the loginpocess.php grad those values using $_REQUEST and do your job.... Edited April 12, 2013 by subhomoy Quote Link to comment Share on other sites More sharing options...
wright67uk Posted April 12, 2013 Share Posted April 12, 2013 Also your form should be within the <body> and </body> tags opposed to the head tags. Good luck with your learning! Quote Link to comment 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.