php

How can I display only the query string witch is john and not any of the extra stuff like demo=


I am using this php script (see below) when someone enters http://website.tld/index.php?demo=john this pulls the page named "john" from the actions folder and displays it at http://website.tld/index.php?demo=john. I have been trying to play around with different type of codes and not much has been a success by giving me 500 error status, anyway I found this php code <?php echo $_SERVER['QUERY_STRING'] ?> witch gives me what I want some what of what I wanted but not quite exactly as I only want to display john and not show demo=, what can I do to achieve this?

$page = $_POST["demo"];
if($page == null)
{
        $page = "actions/users.php";
}

if (file_exists("actions/$page.php"))
{
        include ("actions/$page.php");
}
else
{
        include ("actions/404.php");
}
?> ```

Solution

  • $_POST[] is typically used to handle form data via the POST method.

    If you want to get a parameter value from query string, you can use $_GET['demo']. I hope this helps!