Get the full URL in PHP
Have a look at $_SERVER['REQUEST_URI']
, i.e.
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
(Note that the double quoted string syntax is perfectly correct)
If you want to support both HTTP and HTTPS, you can use
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
Editor's note: using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value it wants.
Get current URL path with query string in PHP
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'
.
How to get the full URL of the current page using PHP
You can use this for HTTP request
<?php $current_url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
You can use this for HTTPS request
<?php $current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
You can use this for HTTP/HTTPS request
<?php $current_url="//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
How to get URL of current page in PHP
$_SERVER['REQUEST_URI']
For more details on what info is available in the $_SERVER array, see the PHP manual page for it.
If you also need the query string (the bit after the ?
in a URL), that part is in this variable:
$_SERVER['QUERY_STRING']
how to catch the full url including #
Plz Refer Below Link
Get Full Url in PHP
at Client Side You can use javascript to get hash value with window.location.hash
Getting the full URL of the current page (PHP)
function selfURL()
{
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
Trying to get a full URL without filename in PHP
There won't be one because it's not a useful attribute to track. If the current script is something other than index.*
then it will not return the correct URL for the current script.
However, this might get you what you want:
echo '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
Edit:
Also, aside from installing the php.net online manual search tool for Firefox and setting it up with a search keyword (which will let you pull up the documentation on the $_SERVER
global by typing something like "php $_server
" into your URL bar), you should also know that var_dump()
and print_r()
lets you output the full contents of any variable, including arrays and objects. This is very useful for debugging.
PHP Get URL with Parameter
basename($_SERVER['REQUEST_URI']);
This will return all URLs with page name. (e.g.: index.php?id=1&name=rr&class=10
).
Related Topics
How to Show Blob Image in HTML
How to Get the Path to the Laravel Storage Folder
Laravel: Pdoexception: Could Not Find Driver
How to Throw an Error Message If Username Is Already Registered
Download a Facebook Video (.Mp4) Via PHP
How to Get Next Id of Autogenerated Field in Laravel for Specific Table
Sql Get an Id from a Column Where Ids Separated by Commas
How to Submit Multiple PHP Forms While Each Form Has Its Own Submit Button
How to Prevent Mails Sent Through PHP Mail() from Going to Spam
Laravel Composer Sees Wrong PHP Version
Fatal Error: Call to Undefined Function Mysqli_Connect()
Laravel 6: Call to Undefined Method App\\User::Createtoken()
Cross-Origin Request Headers(Cors) With PHP Headers
How to Count Occurrence of Duplicate Items in Array
How to Use Return Inside a Recursive Function in PHP
Check If Class Property Is Not Null Before Calling Any Public Class Method