Skip to content
PHP Logo

What is the difference between using $_GET and $_REQUEST to retrieve variables from the URL in PHP?

Using $_GET is more secure and recommended when retrieving variables from the URL in PHP because it only retrieves variables passed through the URL query string. On the other hand, $_REQUEST retrieves variables from multiple sources including $_GET, $_POST, and $_COOKIE, which can potentially lead to security vulnerabilities if not handled properly.

php
// Using $_GET to retrieve variables from the URL
$variable = $_GET['variable'];