Common PHP Tasks and Questions
Web Pages With Variable Content
How do I include variable content in a PHP page?
You may have seen on quite a few sites when they link to a file they just link to "www.example-domain.com/?page=pic.html&pic=jane-austin.jpg" or such. The idea is to link to a PHP page that includes the selected picture inside a web page without having to make a separate html file for every single picture, for example.
Unless you need to apply a universal template to the pages, you can simply make this a PHP page that accepts and displays variable content. PHP is a preprocessor, which means it automatically reads the page and executes code it finds. Any variables from a link are automatically brought into existence.
For this example, If you do not need templates to be varied by the image, just create a PHP page with whatever HTML you want on it, then include:
$inf = getimagesize("pictures/".$pic);
print '<img src="pictures/'.$pic.'" '.$inf.' alt="">';
If the page is index.php, you can call it with only the domain name
or by specifying a directory:
|Pages: 1 2 3 4||Next: Basics of Accessing the CGI Enviroment »|