?
Solved

Display Different Graphic On Each Page

Posted on 2014-09-25
6
Medium Priority
?
95 Views
Last Modified: 2014-10-09
Hi,

I need to display a different graphic on each page of my site (in the top header).

www.mywebsite.com = graphic01.png
www.mywebsite.com/about = graphic02.png
www.mywebsite.com/contact = graphic03.png
www.mywebsite.com/portfolio = graphic04.png
www.mywebsite.com/services = graphic05.png

Then for all other pages, i just want to display the default graphic (graphic-default.png).

What would be the best way to accomplish this using PHP, thanks in advance for your help.
0
Comment
Question by:oo7ml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 40343866
PHP is self-aware.  You can locate $_SERVER['REQUEST_URI'] and test the value to see if the strings "about", "contact", etc. are present in the variable.  You can use an array to map the names of the pages to the names of the graphics, and choose the right one with an if() statement or a switch() statement.
0
 
LVL 11

Accepted Solution

by:
Chris Gralike earned 1000 total points
ID: 40345958
Code example based on Ray's comment.

<?php
// See http://php.net/manual/en/reserved.variables.server.php for more info on $_SERVER superglobal.

switch($_SERVER['REQUEST_URI']) {
                      case '/about':
                             echo '<img src="./images/graphic02.png" />';
                             break;
                      case '/contact':
                             echo '<img src="./images/graphic03.png" />';
                             break;
                       // etc
                      default:
                             // Mainpage (or case '/' for performance)
                             echo '<img src="./images/graphic00.png" />';
                             break;
}
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40346025
@Chris: just wondering - did you test that code?
0
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
LVL 11

Expert Comment

by:Chris Gralike
ID: 40346082
As a matter of fact i did.
Why you ask?

EE-contact-.png

(I admit the example is loosely written and requires url rewrite to be configured. It will be more stable using basename and various checks)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40346144
Just thinking out loud - what if there is a URL parameter request variable?  I think it might be worth isolating the desired substring(s) from the URL.  After I wrote, "switch()" I got to thinking that maybe it wasn't the right application for switch()!
0
 
LVL 11

Expert Comment

by:Chris Gralike
ID: 40346186
My code doesn't handle that at all and in my opinion it should not.

Its an example that needs refinement (sure). But an example non the less. Copy-pasting any example in production without a second thought and precise consideration is bad practice in any situation. It should be rewritten to answer the requirements set out by the user matching its context, and thus needs 'work' ;-)

On how to overcome the risk you set out without masses of code, is by url rewrite: https://wiki.apache.org/httpd/RewriteQueryString. But this in my opinion is a different question.

But!
of course you are absolutely right the code in the example is a huge risk without additional coding.
0

Featured Post

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question