Saud Kazia
Saud Kazia

Reputation: 89

Generate PHP page based on URL

Apologies if this has been asked before. Basically I did a search on Google and found nothing relevant.

I want to be able to create a template and use that template to generate dynamic content based on the URL.

So if I go to mydomain.com/mypage.php?img=source

It should generate my mypage.php template and change the img or any other content source to that of "source"

so if I go to mydomain.com/mypage.php?img=bird

my mypage.php will show and the image or other content whose variable needs to be changed will output bird

I hope that is clear

Upvotes: 1

Views: 335

Answers (3)

Saud Kazia
Saud Kazia

Reputation: 89

well. apparently in order to achieve what i wanted, i need to use MYSQL so that the information can be retrieved via a query. none of the other answers met my requirement.

this website helped a lot with a tutorial which i was able to tinker with and achieve my requirement -> http://www.vdesignourweb.com/cmsphpsqlb/cms_intro.html

Upvotes: 0

Leon
Leon

Reputation: 25

Ok, I keep adding stuff to this!

<?php
    if(isset($_REQUEST['img'])) {
    }
    else {
        $_REQUEST['img'] = "false";
        $image = "false";
    }
    $image = $_REQUEST['img'];
    $image = strtolower($image);
    if ($image == 'false'){
        $content = 'no image specified';
    }
    else{
        $content = print '<img src="images/'.$image.'.jpg">';
    };
?>

To change the image size, you could just add a width and height before src.
Then, to print the image, all you have to do is add this where you want it to show:

<?php print $content; ?>

Upvotes: 0

benomatis
benomatis

Reputation: 5633

Try this:

if ($_GET['img'] == 'source') {
    // do stuff
} elseif ($_GET['img'] == 'bird') {
    // do other stuff
} else {
    // do stuff if 'img' is not set or is empty
    // or just none of the above
}

Upvotes: 4

Related Questions