📘 Lesson  ·  Lesson 12

PHP Forms ($_POST / $_GET)

PHP Forms ($_POST / $_GET)

Handling Forms in PHP

PHP reads submitted form data through $_POST (hidden in the request) and $_GET (visible in the URL). Forms are the heart of dynamic websites.

The HTML Form

<form method="post" action="welcome.php">
  Name: <input type="text" name="username">
  <input type="submit" value="Submit">
</form>

The PHP Handler

<?php
  $name = $_POST["username"];
  echo "Welcome, " . htmlspecialchars($name);
?>
Welcome, Aman

Always Sanitize Input

Never trust user input. Use htmlspecialchars() on output and validate/filter data to prevent XSS and other attacks.

Summary

  • $_POST reads hidden form data; $_GET reads URL data.
  • Always sanitize with htmlspecialchars() and validate input.

PHP में Forms संभालना

PHP submitted form data $_POST (request में छुपा) और $_GET (URL में दिखता) से पढ़ती है। Forms dynamic websites का दिल हैं।

HTML Form

<form method="post" action="welcome.php">
  Name: <input type="text" name="username">
  <input type="submit" value="Submit">
</form>

PHP Handler

<?php
  $name = $_POST["username"];
  echo "Welcome, " . htmlspecialchars($name);
?>
Welcome, Aman

हमेशा Input Sanitize करें

User input पर कभी भरोसा न करें। XSS और दूसरे attacks रोकने को output पर htmlspecialchars() use करें और data validate/filter करें।

सारांश

  • $_POST छुपा form data पढ़ता है; $_GET URL data।
  • हमेशा htmlspecialchars() से sanitize करें और input validate करें।
← Back to PHP Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।