Home » How to get the current page name using PHP?

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.

Read Also:  Laravel Group By Count Multiple Columns

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:  Codeigniter Fullcalendar Example Tutorial From Scratch

$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:  Get last inserted ID laravel 5.7 Examples

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel 6 Eloquent Model Increment Decrement
  2. Read Also:  failed to load resource: the server responded with a status of 404 (not found)
  3. Read Also:  Laravel Time Zone Converter(Time Difference Calculator)
  4. Read Also:  Simple Ecommerce PHP Shopping Cart Application
  5. Read Also:  Laravel 5/6/7 create custom helper Function
  6. Read Also:  How To Find The Second Highest Salary In SQL Server?
  7. Read Also:  Bitcoin Altcoin Ethereum Cryptocurrency Exchange Script
  8. Read Also:  PHP Sorting Arrays Tutorial With Examples
  9. Read Also:  Get the full URL in PHP
  10. Read Also:  Task Scheduling with Cron Job using Laravel 5/6/7

Leave a Comment

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