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

  • Home
  • SEARCH
  • 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 8492413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:42:43+00:00 2026-06-10T22:42:43+00:00

I want to let user input two variable, Name and Password in a form.

  • 0

I want to let user input two variable, Name and Password in a form. I want to disable any XSS or script insert in the input values. I have the following code in the form method:

<form name="form1" method="post" action="checkpw.php">
Your Name:
<table>
  <tr><td><input class="text" name="name" onBlur="capitalize(this);" maxlength=12 type="text" /></td></tr>
</table> 
Password:
<table>
  <tr><td><input class="text" name="passwd" maxlength=8 type="password" /></td></tr>
  <tr><td align="center"><br/>
     <input class="text" type="submit" name="submitbt" value="Login" />
  </td></tr>
</table>  

and the following checkpw.php:

<?php

// Clean up the input values 
$post = filter_input_array(INPUT_POST, array(
    'name' => FILTER_SANITIZE_STRING,
    'pw' => FILTER_SANITIZE_STRING,
));

if (is_null($post) || in_array(null, $post)) {
    header("location:login.php");
    return; // missing fields (or failed filter)
} 

// pw is the password sent from the form 
$pw=$_POST['passwd'];
$name=$_POST['name'];

if($pw == 'testpass'){
    header("location:index.php");
} else {
    header("location:wrong.php");
}
?>

Is this a secure way to ensure the form is sent to the server and executed ONLY after the input values have been sanitized?

Also, the $name value i want to pass it to index.php file. I insert a code in the index.php as follow:

<?php echo $name ?>

But it’s empty. Any idea how to resolve it?

  • 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-06-10T22:42:44+00:00Added an answer on June 10, 2026 at 10:42 pm

    The magic_quotes_gpc should be disabled on most servers by now; however, do read this article to see other ways of disabling them.

    Furthermore, you can use filter_input_array() (PHP >= 5.2) for this purpose:

    $post = filter_input_array(INPUT_POST, array(
        'name' => FILTER_SANITIZE_STRING,
        'pw' => FILTER_SANITIZE_STRING,
    ));
    
    if (is_null($post) || in_array(null, $post)) {
        return; // missing fields (or failed filter)
    }
    
    // you can safely use $post['name'] and $post['pw'] here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I want a user to input two strings (name and email, let's say)
i want to let the user type in the name of a new file,
i want to read 2 values from user input using lisp. I want to
I want to let the user input their own town/city and country, so I
This is what I want : Let the user enter as many numbers as
I have a Multiline Textbox . I donot want to let user type HTML
So I have a file for constants. I want to let user define them
I want to let the user download the current content of a textarea into
I'm using jquery ui draggable, I do not want to let the user drag
Selenium provide many kinds of browser driver, so I want to let the user

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.