Do you want to get the current page URL in PHP then check this code below?
In this trick, we will use the $_SERVER super global variable and get the server name, protocol, server port, and request URL. You just have to check these values on specific conditions and then you will get the correct current page URL.
In the above code, first, we check the protocol to HTTPS or HTTP then we get the server name. After that, we make a condition to check the server port and then get the request URI.
Finally, you will get the current page URL, when you call this function in your PHP code.
Being Tricky 😉