
PHP to Shell, Part 1-6: Your First PHP App
Part 1 of 6 > Your First PHP App
Takeaway: include() runs whatever path you hand it — including one an attacker chose.
After this lesson you can write and run a real PHP app from a blank directory, explain what a
superglobal is because you printed one, and explain what include() does because you watched it
pull a file in. No PHP background assumed. If you know curl and HTTP, that’s enough.
The whole app is two files
Make a directory and put one text file in it:
$ mkdir app && cd app
$ printf 'about page\n' > about.txt
Now write index.php:
<?php
echo "Method: " . $_SERVER['REQUEST_METHOD'] . "\n";
echo "GET params: ";
print_r($_GET);
$_SERVER and $_GET are superglobals — arrays PHP fills in for you, automatically, before
your code runs. $_SERVER holds request metadata (method, headers, paths). $_GET holds the
query-string parameters from the URL. You never populate either one yourself; PHP hands them to
you already built.
Run it with PHP’s built-in development server, no Apache, no Docker, no config file:
$ ls
about.txt
index.php
page.php
$ php -S 127.0.0.1:8000
[Tue Nov 17 2026 18:00:10] PHP 8.4.23 Development Server (http://127.0.0.1:8000) started
That one command serves the current directory over HTTP. Leave it running and, from another terminal, ask it for something:
$ curl "http://127.0.0.1:8000/index.php?name=rookie&debug=1"
Method: GET
GET params: Array
(
[name] => rookie
[debug] => 1
)
That’s the array from the earlier claim, printed back at you. name and debug never appear
anywhere in index.php — PHP read them off the query string and populated $_GET before the
first line of your script executed. A superglobal isn’t a concept to take on faith; it’s
something you can print_r() and read.
A second file that picks a file for you
Real sites don’t hardcode every page. A common shortcut is to let one URL parameter choose which
file to render. Write page.php:
<?php
include($_GET['page']);
include() takes a path and pulls that file’s contents into the current script, as if you had
pasted them there by hand. If the file is plain text, PHP prints it. If the file is PHP code, PHP
runs it. include() doesn’t know or care which — it does the same thing either way.
Ask page.php for about.txt:
$ cat page.php
<?php
include($_GET['page']);
$ curl "http://127.0.0.1:8000/page.php?page=about.txt"
about page
One line of code, and the query string decided which file got read. That’s the entire feature:
“let visitors pick a page” in a single include() call. It works, it’s five characters shorter
than a switch statement, and plenty of real code looks exactly like this.
Key point:
page.phphas no list of allowed pages anywhere in it. The only thing deciding which file gets included is whatever string sits after?page=.
Try it: add a second page, no code changes
Prove to yourself that include() is reading the path, not something baked into page.php:
$ printf 'contact page\n' > contact.txt
$ curl "http://127.0.0.1:8000/page.php?page=contact.txt"
contact page
Nobody edited page.php between those two curl calls. The file didn’t change — the parameter
did, and include() followed it. If that felt unremarkable, that’s the point: this lesson has no
trick in it yet. page.php is doing exactly what it looks like it’s doing.
Part 2 asks the only question that matters from here: what happens when ?page= points
somewhere you didn’t intend it to. The two files in your app/ directory right now —
index.php and page.php — are the same two files every remaining lesson in this series uses.
Nothing gets rebuilt; it gets broken, one line at a time, starting with the line you just wrote.
Related posts
03 ENTRIEShttps://shulkwisec.github.io/php-to-shell/01-your-first-php-app/
Printed 2026-11-24

