Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP echo for image tags...


  • Please log in to reply
4 replies to this topic

#1 Doug E Fresh

Doug E Fresh

  • Members
  • 224 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:New Jersey/Miami
  • Local time:12:24 PM

Posted 30 August 2011 - 04:07 PM

Hi,

Recently a site I built for my job has been sent off to our IT guys to be converted to PHP. When they did this they changed all my typical HTML image tags to this: <img src="<?php echo IMAGES_ROOT;?>contact.png" />

I'm hoping someone can tell me what the point of this is. It seems like it's another layer of code that's going to make my job more complicated, so I'm hoping there's a good reason. Thanks.

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:24 AM

Posted 30 August 2011 - 04:13 PM

Because then the links can be dynamically changed without changing the markup. All dynamic websites combine html, javascript, and something like php, or asp, or java, etc. In the example you gave there, the IMAGES_ROOT defines a constant that tells the browser where the image fields are located. If they ever decide to change that location, then all they need to do is update that single variable.

#3 Doug E Fresh

Doug E Fresh
  • Topic Starter

  • Members
  • 224 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:New Jersey/Miami
  • Local time:12:24 PM

Posted 30 August 2011 - 05:45 PM

Well, that makes sense, I guess. It's kind of hard to wrap my brain around while digging through this code. I've been struggling to learn PHP here and there for months.

So in my index they have a call for a file called common.php, and in it it says:

require_once ($_SERVER['DOCUMENT_ROOT']."/include/config/define.php");

Inside define.php there's a long list of 'stuff', including:

define("IMAGES_ROOT", RESOURCES_URL."images/");

which leads me to:

define("RESOURCES_URL", INCLUDE_URL."resources/");

I guess they have some kind of reason for this seemingly long trail of breadcrumbs. Even my CSS files are now PHP. I guess this makes more sense when you know what you're doing, huh? Thanks for the help, I appreciate it.

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:24 AM

Posted 31 August 2011 - 06:56 AM

The require_once just means to include a file of constants. Again, this is not unusual. The 'defines' are just that, they define constants. I don't know what they are trying to accomplish with the example you included above, but it appears that they are just trying to program in as much flexibility as possible. You will appreciate it more when you need to do updates, providing of course there is someone with the knowledge of what is going on and why.

#5 cryptodan

cryptodan

    Bleepin Madman


  • Members
  • 21,868 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Catonsville, Md
  • Local time:04:24 PM

Posted 31 August 2011 - 02:46 PM

the includes folder or directory of a website contain the framework for the site to be built around. Its much like the skeleton of the site.

It saves time for coding and production. It also allows you to make changes on the fly without having to go back into the raw HTML and edit every instance of something that requires a change.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users