1

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

Engineer2021
  • 3,288
  • 6
  • 29
  • 51
Saud Kazia
  • 89
  • 1
  • 9
  • 1
    Yeah, it's very clear. So what's the problem? – Jakub Matczak Apr 19 '14 at 08:39
  • Please see my comment to @Leon's answer. – Victory Apr 19 '14 at 08:50
  • hi. sorry to revive this dead question. i didn't follow up during the time. if i could re open this question, i am having the same issue and the answers do not meet my requirement. see once i create mypage.php template, a spot should be designated in the code so when i go to mypage.php?img=bird -> the page will open with the same structure as mypage.php but where the designated spot for for img is bird (which can be defined as a variable in another page or some other way) the whole point is so i don't have to create a new page for each change in content. – Saud Kazia Sep 05 '14 at 13:10
  • Have you tried my solution? simly put that code on `mypage.php` in the middle, wherever you wanted the content to change, therefore keeping the template intact... – benomatis Dec 21 '14 at 09:06
  • thanks. but i got my answer by using cms solution. – Saud Kazia Jan 06 '15 at 13:54

3 Answers3

4

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
}
benomatis
  • 5,536
  • 7
  • 36
  • 59
0

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; ?>
Anonymous
  • 11,748
  • 6
  • 35
  • 57
Leon
  • 25
  • 8
  • 3
    -1 because you have no mention of XSS, no mention of `htmlspecialchars` for instance. http://stackoverflow.com/questions/1996122/how-to-prevent-xss-with-html-php – Victory Apr 19 '14 at 08:49
  • this is an answer, he said he wanted to have ?img=bird This allows use of images to be put into the images folder and not have to edit the code on the file – Leon Apr 19 '14 at 12:43
0

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

Saud Kazia
  • 89
  • 1
  • 9