How to get the current page name using PHP?

Today, We want to share with you php get page name.In this post we will show you php current pages name without path, hear for Get current pages name PHP we will give you demo and example for implement.In this post, we will learn about PHP Get Current URL Full Path HTTP-HTTPS Protocol with an example.

PHP: Get Current Page Name

There are the Following The simple About How to get the current pages name using PHP? Full Information With Example and source code.

As I will cover this Post with live Working example to develop php get full url with parameters, so the php get current url with query string is used for this example is following below.

Get the current page name without extension using PHP

$all_page_info = pathinfo( __FILE__ );
$getCurrentPageName = $all_page_info['filename'];  
print_r($getCurrentPageName); //results : index

The main useful PHP pathinfo() function data returns an array that all the contains the details all about a path. like as a filename key holds the file name(.php, .html, .txt) without any types of the extension therefor it will return the page name only.

Read Also:  Laravel Combine two DB query results Example

$getCurrentPageName = pathinfo(__FILE__, PATHINFO_FILENAME); 
print_r($getCurrentPageName); //results : index

Also, the above line of code returns the current/active page name without extension. But, I will recommend you to use $_SERVER[‘PHP_SELF’] instead of __FILE__. Because if the code ran from another file then it would break.

$getCurrentPageName = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME); 
print_r($getCurrentPageName); // results : index

Get the current page name with extension using PHP

$getCurrentPageName = basename($_SERVER['PHP_SELF']); 

print_r($getCurrentPageName); // results : index.php

The above PHP Source code returns the current/active getCurrentPageName with file name extension.

Read Also:  Laravel 6 Eloquent Global Scope Tutorial Example

If you face any issue feel free to inform me in the comment section following. Please like and share this article how to get the current pages name using PHP with others more imp Post.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *