$_SERVER
Superglobal VariableYou can use the $_SERVER
built-in variable to get the current page URL in PHP. The $_SERVER
is a superglobal variable, which means it is always available in all scopes.
Also if you want full URL of the page you'll need to check the scheme name (or protocol), whether it is http
or https
. Let's take a look at an example to understand how it works:
<?php
$uri = $_SERVER['REQUEST_URI'];
echo $uri; // Outputs: URI
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $url; // Outputs: Full URL
$query = $_SERVER['QUERY_STRING'];
echo $query; // Outputs: Query String
?>
i hope you like this small article.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Twitter API OAuth 2.0 Authorization Example
Twitter is one of the most powerful soci...Laravel 5.6 - Card Payment Integration With Instamojo Payment Gateway
Today, we are share with you how to inte...Laravel 5.5 - Razorpay Payment Gateway Integration
Today, we are share with you in this tut...How to check if an element is hidden using jQuery
Use the jQuery :hidden Selector The j...How to find number of characters in a string in PHP
Use the PHP strlen() function...