How to get the full URL of the current page in PHP?
Hello everyone! I'm a beginner in PHP and trying to write a simple logging system that records which page a user visits the site from. I need to get the full URL of the current page, including the protocol (http/https), domain, and all GET parameters.
I tried using `$_SERVER['REQUEST_URI']`, but it only returns the path, for example `/page.php?id=123`. But I need something like `https://mysite.com/page.php?id=123`. I tried combining it with `$_SERVER['HTTP_HOST']`, but in some cases I get errors, especially when the site is running over HTTPS.
Here is my current code:
```php
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
```
The problem is that:
1. HTTPS is not taken into account
2. Sometimes `HTTP_HOST` is missing or contains a port
3. On the local server (OpenSer
No answers yet.
Log in to leave an answer