Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/130980-solved-wondering-if-i-can-do-this/
Share on other sites

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

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

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

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?

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;

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

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

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

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

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]

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

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

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

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.