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

5
  • 1
    Yeah, it's very clear. So what's the problem? Commented Apr 19, 2014 at 8:39
  • Please see my comment to @Leon's answer. Commented Apr 19, 2014 at 8: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. Commented Sep 5, 2014 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... Commented Dec 21, 2014 at 9:06
  • thanks. but i got my answer by using cms solution. Commented Jan 6, 2015 at 13:54

3 Answers 3

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
}
Sign up to request clarification or add additional context in comments.

Comments

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; ?>

2 Comments

-1 because you have no mention of XSS, no mention of htmlspecialchars for instance. stackoverflow.com/questions/1996122/…
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
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.