Jump to content

Basic Question


lukenichols

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites


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.


Link to comment
Share on other sites

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 by subhomoy
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.