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 12-20-2003, 07:10 PM   PM User | #1
MeGa
New Coder

 
Join Date: Dec 2003
Location: Miami, FL
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
MeGa is an unknown quantity at this point
non-PHP files

would it be a good idea to include (or link to) non-PHP files in this way:
src="http://<?php echo $_SERVER['HTTP_HOST']; ?>/images/banner.png"
or
src="http://<?php echo $_SERVER['HTTP_HOST']; ?>/snow.js"

any comment very appreciated

BTW, how about php files?
__________________
MeGa MaX
Be the Best, but don't Believe it.
MeGa is offline   Reply With Quote
Old 12-20-2003, 10:34 PM   PM User | #2
SpeedFreak
Regular Coder

 
Join Date: Sep 2002
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
SpeedFreak is an unknown quantity at this point
i dont see what advantage that has over just typing in the host address, unless the site changes domains often...
SpeedFreak is offline   Reply With Quote
Old 12-21-2003, 12:12 AM   PM User | #3
SDP2006
Regular Coder

 
Join Date: May 2003
Location: 34° 54' N 82° 13' W
Posts: 996
Thanks: 0
Thanked 0 Times in 0 Posts
SDP2006 is an unknown quantity at this point
Yeah, that saves you no time whatsoever and is rather pointless.
__________________
Stevie Peele
Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
#dev - any programming,etc. question
#design - design discussion and critque
#central - general chat
Come join us!
SDP2006 is offline   Reply With Quote
Old 12-21-2003, 09:38 AM   PM User | #4
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,942
Thanks: 7
Thanked 82 Times in 81 Posts
firepages will become famous soon enough
If you intend to reuse your code (which is a good thing) then your basic idea is far from pointless, as you can reuse that code on any site without worrying about changing it.

Personally I define a variable in a config file (the same place I keep database connections etc , e.g. a file that is always included and ..

PHP Code:
<?
define
'ROOT' 'http://www.domain.com/' ) ;
define'FILE_ROOT' '/home/user/www/' ) ;
define'TEMPLATES' FILE_ROOT '/admin/tpl/' ) ;
/* etc.. */
?>
& then e.g.

src="<?=ROOT;?>images/banner.png">

etc , so whenever I reuse a block of code I never ever have to worry about search & replacing code left right and centre.
OK your code above is simple , but you will find that most larger complex projects will be using very similar logic , even down to defining image and script and user paths & directories etc.

( <?=ROOT;?> is also ( 9/10 ) less typing )
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 12-21-2003, 11:33 AM   PM User | #5
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
whats wrong with src="/images/header.gif" as this reads from the root directory anyway.
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 12-21-2003, 12:00 PM   PM User | #6
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,942
Thanks: 7
Thanked 82 Times in 81 Posts
firepages will become famous soon enough
absolutely nothing , but then you may for example decide to use search engine friendly URL's eg

page.php/var1/var2/etc
instead of
page.php?var1=var1&var2=var2 .... etc

now you have to recode all of your paths as the links now requires an extra '../' or two (or 3)

now thats just 1 example which happens to fit my preference

however coding absolute paths and then abstracting those puts you in a position where you simply can not lose.

I would say that 50-60% of my day to day work now reuses existing code , especially for generic frameworks of sites/applications , at this point simple steps such as MeGa suggests can reap massive benefits , the more complex the applications get , the more sense it makes.

The ONLY downside to the above is the extra parsing that PHP has to do , and that would be a fair argument on its own , but firstly the overhead is minor , however if you are an efficiency freak (like me) then you negate that overhead with cacheing , be that administrative or at runtime.

The point I am trying to make is that the method noted is not useless , again , far from it and it should not be dismissed without thought.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Reply

Bookmarks

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 04:11 PM.


Advertisement
Log in to turn off these ads.