Q:

Using PHP $_GET to grab data and define content

I want to use PHP's $_GET in a url to grab data to help define content within the page.
Basically, I want the url to be like this-
/page.php?p=1
Then, the PHP would automatically include ../content/1.txt later in the code, because 1 was after p=. If the url was /page.php?p=2, then it would include ../content/2.txt because that was in the url. I want it to do this automatically, and within the page, so that a basic skeleton can be put together, and the file is included in that skeleton. I want PHP to do this automatically, instead of having to define every single p= and have it get it from that. 

A:

page.php:
if(isset($_GET['p']) && is_numeric($_GET['p'])){
    include('../content/'.$_GET['p'].'.txt');
}

A:

Try something like this...
<?php

    if(isset($_GET['p'])){

        $fileName = $_GET['p'];

        /* validate the user input here */

        $fileName = "../content/" . $fileName . ".txt";

        //include the file
        include($fileName);

        //or echo a link to the file
        echo "<a href=\"" . $fileName . "\">Link</a>";

        //or echo the file's contents
        echo file_get_contents($fileName);
    }
?>

