toothmkr57 Posted November 1, 2008 Share Posted November 1, 2008 In my header if I have an img src="blah.com/somepic.jpg" then can I change it somehow to look at the subdomain? For instance can I have img src="$something", but if it is subdomain_2 it is something_2.jpg, if it is subdomain_3 it is something_3.jpg, etc......" Is there anyway to write that variable? Thanks, Paul Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/ Share on other sites More sharing options...
RichardRotterdam Posted November 1, 2008 Share Posted November 1, 2008 I think you're looking for $_SERVER['SERVER_NAME']; you can just use the if statement to change the src attribute of the image Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-679948 Share on other sites More sharing options...
toothmkr57 Posted November 1, 2008 Author Share Posted November 1, 2008 ok, really I'm just a noobie and I know just about nothing, so while I can see this going in the right direction, I need a little more direction. I want to learn so I don't necessarily want it done completely, but maybe some direction with a gentle push on a tutorial that will help my specific want. I've been all over w3schools, but I'm not quite familiar enough to complete the thought. Thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680200 Share on other sites More sharing options...
RichardRotterdam Posted November 1, 2008 Share Posted November 1, 2008 to point you a little more into the right direction try the following code <?php $domain=$_SERVER['SERVER_NAME']; echo($domain); ?> run that on the different subdomains. the values should be different so you can use that like so <?php $domain=$_SERVER['SERVER_NAME']; echo($domain); //your image url $imgUrl=""; if($domain=="yoursubdomain1"){ $imgUrl="image1.jpg"; }elseif($domain=="yoursubdomain2"){ $imgUrl="image2.jpg"; } ?> you can also use a switch statement which would tidier but I think you get the idea Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680215 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 So is it kinda like this then? <?php $domain=$_SERVER['SERVER_NAME']; echo($domain); //your image url $imgUrl="http://www.pmcsravenstone.com/media/"; if($domain=="http://webdesign.pmcsravenstone.com"){ $imgUrl="web.png"; }elseif($domain=="http://dental.pmcsravenstone.com"){ $imgUrl="dental.png"; }elseif($domain=="http://family.pmcsravenstone.com"){ $imgUrl="family.png"; }elseif($domain=="http://fun.pmcsravenstone.com"){ $imgUrl="fun.png"; }else($domain=="THIS IS WHAT i REALLY DON'T KNOW WHAT TO PUT FOR THE DEFAULT is it just the whole url? "){ $imgUrl="bridge.png"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680324 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 Would this be acceptable for the switch method? <?php $domain=$_SERVER['SERVER_NAME']; echo($domain); $imgUrl="http://www.pmcsravenstone.com/media/"; switch ($imgUrl) { case 1: if($domain=="http://webdesign.pmcsravenstone.com"){ $imgUrl="web.png"; break; case 2: if($domain=="http://dental.pmcsravenstone.com"){ $imgUrl="dental.png"; break; case 3: if($domain=="http://family.pmcsravenstone.com"){ $imgUrl="family.png"; break; case 4: if($domain=="http://fun.pmcsravenstone.com"){ $imgUrl="fun.png"; break; default: if($domain=="http://www.pmcsravenstone.com"){ $imgUrl="bridge.png"; } ?> Or did I just frankenstein slaughter that? Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680327 Share on other sites More sharing options...
laffin Posted November 2, 2008 Share Posted November 2, 2008 From switch ($imgUrl) To switch ($domain) Repetitive, just follow the pattern From case 1: if($domain=="http://webdesign.pmcsravenstone.com"){ $imgUrl="web.png"; break; To case "http://webdesign.pmcsravenstone.com": $imgUrl="web.png"; break; Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680410 Share on other sites More sharing options...
RichardRotterdam Posted November 2, 2008 Share Posted November 2, 2008 I noticed you have this in your code <?php $imgUrl="http://www.pmcsravenstone.com/media/"; ?> does that mean thats the folder where all images are? if that is so change the lines where you give $imgUrl a value like so: $imgUrl="some.png"; to(add the dot) $imgUrl.="some.png"; that way your image url will always be absolute Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680478 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 Ok, in the switching example corrections why is the switch ($imgUrl) changed to switch ($domain) aren't we actually switching the image, or is it that we are telling the server that if the domain switches then use the prescribed image. in the if statement corrections, when you add dot and it makes it absolute, why do we need to do that? is there any other situations where we use that, or is there a rule that goes along with that dot? Thanks, Paul Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680504 Share on other sites More sharing options...
RichardRotterdam Posted November 2, 2008 Share Posted November 2, 2008 Ok, in the switching example corrections why is the switch ($imgUrl) changed to switch ($domain) aren't we actually switching the image, or is it that we are telling the server that if the domain switches then use the prescribed image. because you are checking the domain to see what image you need to set. the following code switch ($domain) means check what value is inside the domain The way you had it made it check what image you had to determine what image you need in the if statement corrections, when you add dot and it makes it absolute, why do we need to do that? is there any other situations where we use that, or is there a rule that goes along with that dot? Thanks, Paul the dot notation means add example(test it to see what happens) <?php $imgUrl="http://www.pmcsravenstone.com/media/"; $imgUrl.="image.png"; echo($imgUrl);//this will give http://www.pmcsravenstone.com/media/image.png ?> or you could say its short for <?php $imgUrl=$imgUrl."image.png"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680510 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 Ok, wow this shit is hurting my head, but I think I completely get it and had an epiphany. With (x,d)html, css, and other webdesign code you are telling the server WHAT to write/ and how it is arranged. with php, obviously, but i didn't quite get it???, the server is telling the webdesign code HOW to be written... right? It's like reverse engineering, or at least I'm going to have to think of it that way. Thanks for writing that last example Dj Kat when you echo-ed what it would actually write, is what made me understand what was actually going on... much appreciation! Paul Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680547 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 So it would end up being something like this? <?php $domain=$_SERVER['SERVER_NAME']; echo($domain); $imgUrl="http://www.pmcsravenstone.com/media/"; switch ($domain) { case "http://webdesign.pmcsravenstone.com": $imgUrl.="web.png"; break; case "http://dental.pmcsravenstone.com": $imgUrl.="dental.png"; break; case "http://family.pmcsravenstone.com": $imgUrl.="family.png"; break; case "http://fun.pmcsravenstone.com": $imgUrl.="fun.png"; break; default "http://www.pmcsravenstone.com": $imgUrl.="bridge.jpg"; break; } ?> /code] Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680735 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 Alrighty, I gave this a whirl and nothing.... What gives? Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680737 Share on other sites More sharing options...
Andy-H Posted November 2, 2008 Share Posted November 2, 2008 <?php $domain = $_SERVER['SERVER_NAME']; echo $domain; ?> Run that code in the page on its own and tell me the result please. Also the default case doesn't take a condition. default: $imgUrl.="bridge.jpg"; break; } Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680738 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 <?php $domain = $_SERVER['SERVER_NAME']; echo $domain; ?> Run that code in the page on its own and tell me the result please. pmcsravenstone.com Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680747 Share on other sites More sharing options...
Andy-H Posted November 2, 2008 Share Posted November 2, 2008 <?php $domain = $_SERVER['SERVER_NAME']; $imgUrl = "http://www.pmcsravenstone.com/media/"; switch ($domain) { case "webdesign.pmcsravenstone.com": $imgUrl .= "web.png"; break; case "dental.pmcsravenstone.com": $imgUrl .= "dental.png"; break; case "family.pmcsravenstone.com": $imgUrl .= "family.png"; break; case "fun.pmcsravenstone.com": $imgUrl .= "fun.png"; break; default: $imgUrl .= "bridge.jpg"; break; } ?> <img src="<?php echo $imgUrl; ?>"> Does that not work? Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680755 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 no it does not take a look at it an roam the code it you want www.pmcsravenstone.com Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680762 Share on other sites More sharing options...
laffin Posted November 2, 2008 Share Posted November 2, 2008 I see a javascript displaying a pic depending on which menu item is highlighted. dun see many more images on that page Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680797 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 this did not need to be posted something went haywire when I tried to modify... Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680803 Share on other sites More sharing options...
toothmkr57 Posted November 2, 2008 Author Share Posted November 2, 2008 the original code before I switched to trying something php was <div class="headerimg"><img src="http://www.pmcsravenstone.com/media/bridge.jpg" alt="myimage" id="myimg" /></div> Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680805 Share on other sites More sharing options...
RichardRotterdam Posted November 2, 2008 Share Posted November 2, 2008 this <div class="headerimg"><img src="http://www.pmcsravenstone.com/includes/header_image.php" alt="myimage" id="myimg" /></div> should be <div class="headerimg"><img src="<?php echo($imageUrl);?>" alt="myimage" id="myimg" /></div> and the following code should be above that(either with an include or in the page itself) <?php $domain = $_SERVER['SERVER_NAME']; $imgUrl = "http://www.pmcsravenstone.com/media/"; switch ($domain) { case "webdesign.pmcsravenstone.com": $imgUrl .= "web.png"; break; case "dental.pmcsravenstone.com": $imgUrl .= "dental.png"; break; case "family.pmcsravenstone.com": $imgUrl .= "family.png"; break; case "fun.pmcsravenstone.com": $imgUrl .= "fun.png"; break; default: $imgUrl .= "bridge.jpg"; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680825 Share on other sites More sharing options...
toothmkr57 Posted November 3, 2008 Author Share Posted November 3, 2008 Ok. I didn't know that we had to call the php specifically different in the img src"",very interesting. So how does it know to find the seperate php file that I created for it and put in my includes folder? The file was called header_image.php. Also I'm getting the whole switch thing, but just to be specific, why did you put a space between $imgUr' and the dot? Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680832 Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 I did that before just for readability. PHP ignores whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680841 Share on other sites More sharing options...
toothmkr57 Posted November 3, 2008 Author Share Posted November 3, 2008 I did that before just for readability. PHP ignores whitespace. really?!? didn't know that, good to know though, Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680845 Share on other sites More sharing options...
toothmkr57 Posted November 3, 2008 Author Share Posted November 3, 2008 BTW, still not working.... what's next? Quote Link to comment https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/#findComment-680846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.