What are the best practices for integrating JURI::current() in PHP code for Joomla development?

When integrating JURI::current() in PHP code for Joomla development, it is important to ensure that the JURI class is properly included and initialized. This can be done by using the JFactory class to get an instance of the JURI class. Once the JURI class is available, you can use the current() method to get the current URL of the Joomla site.

// Include the Joomla framework
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__);
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';

// Get an instance of the JURI class
$juri = JFactory::getURI();

// Get the current URL
$currentUrl = $juri->current();

// Use the current URL as needed in your code
echo $currentUrl;