This is a PHP function to get the current page URL with only PHP. This works within WordPress, as well.
/** * Get current page url */ function isa_current_url() { $pageURL = 'http'; if( isset($_SERVER["HTTPS"]) ) { if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; }
Example Usage
One use for this is if you’re using ajax to process a form and return results to the page, and you’d like a link below the results to allow the user to “Return to the Form”, or in a sense, refresh the page.
<?php echo '<a class="button" href="'. isa_current_url(). '" title="Refresh this page">'. _('Back To The Form'). '</a>'; ?>
Questions and Comments are Welcome