PHP Web Development

How to get current page URL in php

Our Current url is https://phpgurukul.com/how-to-get-current-page-url-in-php/

$url=$_SERVER['REQUEST_URI'];
echo $url;

Output :
/how-to-get-current-page-url-in-php/ REQUEST_URI  return only  root website folder instead of returning full page.
if you want actual link then use this syntax

$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $actual_link ;

Output :
https://phpgurukul.com/how-to-get-current-page-url-in-php/

In the above code $_SERVER[‘HTTP_HOST’] return the  domain name through which the current request is being fulfilled.

Recommended Tutorials for you


Related posts

How to prevent Cross-Site Request Forgery (CSRF) in PHP

Anuj Kumar

Read, Edit ,Delete and Update data using PHP Prepared Statement

Anuj Kumar

Array in PHP

Anuj Kumar

Functions In PHP

Anuj Kumar

Store Procedure In PHP

Anuj Kumar

String functions

Anuj Kumar

PHP – Data Types

Anuj Kumar

Password Hashing in PHP

Anuj Kumar

PHP – Unique Features

Anuj Kumar

2 comments

Tosin November 10, 2018 at 5:13 am

great works

Reply
Tosin November 5, 2018 at 10:42 pm

great works

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.