Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current URL path with query string in PHP [duplicate]

Tags:

url

php

People also ask

How do I get the current URL in PHP?

To get the current page URL, PHP provides a superglobal variable $_SERVER. The $_SERVER is a built-in variable of PHP, which is used to get the current page URL. It is a superglobal variable, means it is always available in all scope.

How can I get query string values in PHP?

To get the query string from a URL in php, you can use $_GET super global to get specific key value pairs or $_SERVER super global to get the entire string. A query string is a part of a URL that assigns values to specified parameters.

What is Querystring PHP?

A query string is a term for adding/passing data in the URL. It is not language specific.

How get slug URL in PHP?

$slugs = explode("/", $_GET['params']); This will give you an array filled with every element in your URL. This allows you to use each element as you require.


You want $_SERVER['REQUEST_URI']. From the docs:

'REQUEST_URI'

The URI which was given in order to access this page; for instance, '/index.html'.


it should be :

$_SERVER['REQUEST_URI'];

Take a look at : Get the full URL in PHP


<?php
function current_url()
{
    $url      = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $validURL = str_replace("&", "&amp;", $url);
    return $validURL;
}
//echo "page URL is : ".current_url();

$offer_url = current_url();

?>



<?php

if ($offer_url == "checking url name") {
?> <p> hi this is manip5595 </p>

<?php
}
?>