Search code examples
phpmamp

PHP and MAMP - send and read headers


I have set a mamp server on a Mac, and i am sending a request using Safari:

http://localhost:8888

Which works, where the index.php file is this :

$headers = apache_request_headers();

foreach ($headers as $header => $value) {
    echo "$header: $value <br />\n";
}

Question, how would i send and receive some fields together with the address so:

http://localhost:8888/name=me&&city=somecity

then, having some basic PHP code to read each and every field (name/city etc.)?

when i am adding /name=me&&city=somecity to the address I get error.


Solution

  • I have solved it with :

    http://localhost:8888/index.php?name=me
    

    and code: (took for the link provided to me by @hjpotter92)

    <?php
    echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
    ?>