Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: non-PHP files

  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    Miami, FL
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i dont see what advantage that has over just typing in the host address, unless the site changes domains often...

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,077
    Thanks
    11
    Thanked 98 Times in 96 Posts
    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)

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,077
    Thanks
    11
    Thanked 98 Times in 96 Posts
    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)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •