Solved

Display Different Graphic On Each Page

Posted on 2014-09-25
6
94 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 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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 250 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 110

Expert Comment

by:Ray Paseur
ID: 40346025
@Chris: just wondering - did you test that code?
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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 110

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

726 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