Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2012, 10:54 AM   PM User | #1
mulder
New Coder

 
Join Date: Jan 2012
Posts: 30
Thanks: 10
Thanked 0 Times in 0 Posts
mulder is an unknown quantity at this point
deafult image if GET variable is not present

Hey guys, I have a piece of code that enables me to show an image based on an id in the URL. My problem is, I want to show a default image if there is no ID given...Here is my code so far.

Code:
<a href="index.php?id=orange">link</a>
PHP Code:
<img src="http://www.website.co.uk/images/headers/<?php echo $_GET['id']; ?>_index.jpg" border="0">
Hope I have explained myself properly

Thanks in advance
mulder is offline   Reply With Quote
Old 05-25-2012, 11:01 AM   PM User | #2
dan-dan
Regular Coder

 
dan-dan's Avatar
 
Join Date: Aug 2009
Location: England
Posts: 483
Thanks: 22
Thanked 79 Times in 78 Posts
dan-dan is on a distinguished road
Lets assume the default image is called default_index.jpg, you could use this:

PHP Code:
<img src="http://www.website.co.uk/images/headers/<?php echo isset ($_GET['id']) ? $_GET['id'] : "default"?>_index.jpg" border="0">
dan-dan is offline   Reply With Quote
Old 05-25-2012, 12:17 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by iBall View Post
Otherwise you could be displaying images that you would normally not want visible on your website.
http://www.website.co.uk/images/headers/<?php echo isset ($_GET['id']) ? $_GET['id'] : "default"; ?>_index.jpg"

With a semi hard coded file path I very much doubt it unless someone has FTP access.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 05-25-2012, 02:00 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
True, I do recommend the use of file_exists() as you say but I wouldn't worry about a remote person trying to display anything with a hard coded path is what I'm saying.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
mulder (05-29-2012)
Old 05-29-2012, 09:02 PM   PM User | #5
mulder
New Coder

 
Join Date: Jan 2012
Posts: 30
Thanks: 10
Thanked 0 Times in 0 Posts
mulder is an unknown quantity at this point
Sorry for the delay, I have implemented the code above, thank you for your time and help Appreciated!!!
mulder is offline   Reply With Quote
Reply

Bookmarks

Tags
image, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:26 AM.


Advertisement
Log in to turn off these ads.