$_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 harsukh21@gmail.com
How to get Last Record From leftJoin Table in Laravel7?
In this article i will share with you on...Login with Twitter in Angular9 using Firebase
I am going to show you how you can ...How to explode or split a string in JavaScript
Use the JavaScript split() method If...How to Convert JS Object to JSON String
Use the JSON.stringify() Method You c...Laravel 5.5 - How To Make cURL HTTP Request Example
Today, we are share with you how to make...