Skip to content
Related Articles

Related Articles

How to hide credential information form URL while submitting the HTML Form?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 02 Feb, 2022

In this article, we are going to learn how to hide the credential information in the URL while submitting the HTML Form. POST method is used for hiding the credential information. It gets the data from the fields of the HTML form and submits it via the HTTP header without being displayed in the URL. Suppose, If a user enters the credentials as username=GEEKS & password=gfg through an HTML login form on a webpage using the POST method, then the form data is subsequently sent as an HTTP post-transaction.

Given a form and task is to hide the credential information in the URL. For creating a form use HTML as the frontend and PHP code at the backend. The value POST of METHOD attribute of HTML form is used for the purpose of hiding sensitive/personal information from the third party.

Syntax:

<FORM METHOD = "POST">

Values:

  • GET: The form data is appended to the URL in name/value pairs.
  • POST: The form data is subsequently sent as an HTTP post-transaction.

Create an HTML form and use the action attribute to send the request to the mentioned PHP file specified in the code. The method attribute is used to get information or post information filled in the form by the visitor on the webpage using a web browser.

The isset() method is used in PHP to test whether the form is submitted successfully or not. In order to check $_POST[‘submit’] method , use the function isset(). When a user clicks on submit button, this action will work as a POST method and the URL will be like (localhost/login.php) as displayed in the output of the localhost server.

Note: XAMPP or WAMP server can be used for running the program on the localhost server.

Example: The given example will illustrate the working of credential information to be hidden in the URL:

  • Frontend

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Login Form</title>
</head>
  
<body bgcolor="cherry">
    <h2>Login Form Using POST Method</h2>
    <hr>
    <form method="POST" action="login.php">
        Username <input type="text" name="user" 
                  placeholder="Enter Username" size="25">
      <br><br>
        Password <input type="password" name="pass" 
                  maxlength="25">
      <br><br>
        <input type="Submit" value="Submit">
    </form>
</body>
  
</html>

  • Backend

PHP




<!DOCTYPE html>
<?php
    
if (isset($_POST['submit'])) {
    echo "Form is submitted successfully";
}
?>

Output:

So, this is how HTML form data is encrypted and users do not see credentials in the URL of the browser.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!