Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get URL headers in PHP

So, let’s say I’m a client entering this URL on my blog website: https://blogbyme.com/post?id=1.
I want the server to see that URL and customize the page based off what post it is.
The main question is – when the request is made, how do I grab the id header’s value to send the correct blog post?

Right now I’ve got this far.

if (!function_exists('getallheaders')) {
    function getallheaders() {
    $headers = [];
    foreach ($_SERVER as $name => $value) {
        if (substr($name, 0, 5) == 'HTTP_') {
            $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
        }
    }
    return $headers;
    }
}

and that’s still not working.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the superglobal of PHP $_GET:

echo $_GET["id"];

I want the server to see that URL and customize the page based off what post it is. The main question is – when the request is made, how do I grab the id header’s value to send the correct blog post?

You can get the full request URI from:

$_SERVER["REQUEST_URI"]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading