What are some alternative methods to PHP_SELF for form actions in PHP?

Using $_SERVER['PHP_SELF'] in form actions can potentially expose your application to cross-site scripting (XSS) attacks. To mitigate this risk, you can use htmlspecialchars($_SERVER['PHP_SELF']) to sanitize the output and prevent malicious code injection. Another alternative is to use the $_SERVER['REQUEST_URI'] variable, which contains the current URL path.

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
  <!-- form fields here -->
</form>
```

```php
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post">
  <!-- form fields here -->
</form>