Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 789025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:27:38+00:00 2026-05-14T21:27:38+00:00

So right now, I’m just using a basic form to check a password. I

  • 0

So right now, I’m just using a basic form to check a password. I want it to check the password and basically remain on page.html so I can use JavaScript to alert incorrect password or something. I’m not really sure how to do that. It seems it would bring me to check.php. I’m not too sure on the whole process, any help appreciated! Thanks!

Page.html

<form action="check.php" method="post">
    <input type="password" name="password" />
    <input type="submit" value="Submit" />

</form>

check.php

   <?php
    $password = $_POST['password'];
    if ( $password != "testing" ) {
        die();
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:27:38+00:00Added an answer on May 14, 2026 at 9:27 pm

    PHP runs at the webserver which usually runs at a physically different machine (the server side) than where the webbrowser runs (the client side). The machines are usually connected by a network. HTTP is a network protocol. The webbrowser sends a HTTP request. The webserver retrieves a HTTP request whose URL indicates that it should be forwarded to PHP for further processing. PHP retrieves the HTTP request and does the processing and returns a HTTP response. Usually in flavor of a plain vanilla HTML page. The webserver sends HTTP response back to the webbrowser.

    JavaScript runs at the webbrowser and knows nothing about PHP since it runs at the webserver. PHP in turn also knows nothing about JavaScript (although it can produce some JS code which is in turn to be sent to the webbrowser over HTTP). The only way to communicate between JS and PHP is HTTP. One of the ways to let JS fire a HTTP request and retrieve a HTTP response is using XMLHttpRequest. This is the core technique behind Ajax.

    I see in your question history that you’re already familiar with jQuery. It’s a JS library with a lot of convenient functions to fire ajaxical requests. In this specific case you would like to use $.post. E.g.

    $('#formId').submit(function() {
        $.post('check.php', $(this).serialize(), function(valid) {
            if (valid) {
                alert('Valid!');
            } else {
                alert('Invalid!');
            }
        });
        return false; // Important! This blocks form's default action.
    });
    

    With in check.php:

    <?php
        echo $_POST['password'] != "testing";
    ?>
    

    This is however not unobtrusive. If the user has JS disabled, then all will fail. Your best bet is to check in PHP if an ajaxical request is been fired by jQuery or not and handle accordingly:

    if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
        // Ajax.
    } else {
        // No ajax.
    }
    

    Alternatively you can let jQuery also reach a different URL or append an extra parameter.


    Update: here is how the JavaScript would look like when not using jQuery:

    document.getElementById('formId').onsubmit = function() {
        var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                if (xhr.responseText) {
                    alert('Valid!');
                } else {
                    alert('Invalid!');
                }
            }
        }
        xhr.open('POST', 'check.php', true);
        xhr.send(serialize(this));
        return false; // Important! This blocks form's default action.
    }
    
    function serialize(form) {
        var query = '';
        for(var i = 0; i < form.elements.length; i++) {
            var e = form.elements[i];
            if (!e.disabled && e.name 
                && ((e.type != 'checkbox' && e.type != 'radio') || e.checked)
                && (e.type != 'submit' || e == document.lastClicked))
            {
                if (query.length) query += '&';
                query += e.name + '=' + encodeURIComponent(e.value);
            }
        }
        return query;
    }   
    
    document.onclick = function(e) {
        e = e || event;
        document.lastClicked = e.target || e.srcElement;
    }
    

    Bloated and verbose, yes 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 427k
  • Answers 427k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What DB are you running? The only solution to that… May 15, 2026 at 12:55 pm
  • Editorial Team
    Editorial Team added an answer Not in ANSI C, but the Windows API provides a… May 15, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer Here is an example of abusing the preprocessor to implement… May 15, 2026 at 12:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.