SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to name files?

    The website I am building has a combination of mixed page types (e.g. pure HXTML, pure PHP and mixed XHTML/PHP).

    What is the best way to approach naming each file?

    Since I will predomintely be using PHP, I would think I would want to name all files as ".php" even if they just contain XHTML like my index page.

    Thanks,


    Amy

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would call all your pages .php whether or not they have PHP in them, because you may want to add some later and it looks steady this way.
    Sometimes people do this:

    Includes: filename.inc (or) filename.inc.php
    Standard Page: filename.html
    Php page: filename.php
    For classes: Object.class.php

    It may also help to put your includes in a separate folder. Which is what I do.

    I always do all lowercase (unless it's a class file),
    always use - dashes instead of _ underscores, but try to avoid both unless necessary (my preference).

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    If a page contains php code, then yes, it needs a .php extension.

    If there is no php code and is just straight-up HTML, then you can use .htm or .html

    There are probably arguments against using .php extensions on HTML-only pages showing a minuscule performance hit, but for the sake of consistency and possible future addition of php code, I usually put .php on everything if it's at least a partial PHP site.


    But, on the other hand, you can also use an .htaccess rewrite trick to use whatever extension you want (or none at all):

    http://www.google.com/search?hl=en&s...&aq=f&oq=&aqi=
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JREAM View Post
    I would call all your pages .php whether or not they have PHP in them, because you may want to add some later and it looks steady this way.
    Sometimes people do this:

    Includes: filename.inc (or) filename.inc.php
    Standard Page: filename.html
    Php page: filename.php
    For classes: Object.class.php

    It may also help to put your includes in a separate folder. Which is what I do.

    I always do all lowercase (unless it's a class file),
    always use - dashes instead of _ underscores, but try to avoid both unless necessary (my preference).
    Nice reply!

    Okay, one reason I asked this is all of my files are wigging out tonight?!

    UGH!! How to explain?!

    I am trying to build a Seminar Registration System. I am about 2 weeks into learning XHTML, CSS, and PHP. (Hands-on at least!)

    Over the last two weeks, I created all of my webpages as .xhtml with embedded style sheets.

    My first 4 web pages are pure XHTML/CSS. My last 2 pages are PHP/WHTML/CSS.

    Today, to clean things up, I started dissecting things!

    I too out all of my styles and placed them in .css files which are inside my "includes" folder within my "web root".

    All was well, with skinnier XHTML files.

    I then decided to put all of my PHP, XHTML, and/or PHP/XHTML in files called .php The .css files remained the same.

    Now when I load my homepage index.php the Rounded Corners I have on my Navigation Tabs won't show up?!

    I have checked the new paths 100 times, cleaned out browser cache, and yet NOTHING?!

    I don't know what broke?! Same issue locally and on my web host.

    I didn't know if putting pre XHTML is a .php file broke something?!

    Also, I noticed that if I go into Firefox, Tools, Page Info, Media that the URL on my Navigation Tab End GIFs is wrong?! It says something like...

    http://localhost/SeminarRegistration...0_Gray_Rt2.gif

    but the file structure on my HDD is...

    WEB ROOT ---> includes
    WEB ROOT ---> images

    and not...

    WEB ROOT ---> includes ---> images

    I'm dizzy?!

    What is going on????



    Amy

  5. #5
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I figured things out, and am reminded that I really seem to struggle with determining paths...

    Thanks,


    Amy

  6. #6
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha..

    Here these images might help you, they are for small sites -- not the big ones.

    This might help you -- This is how I generally do a site. By the ways these are HTML only because the client had an ASP server (otherwise I always do .php extentions).


    But for most of the time I do it this way (Below),
    #edit is where I store stuff like photoshop PSDs,
    the JS is for Javascript like JQuery,

    I only end up using a folder called 'inc' or 'includes' and put header, footer, nav in there if they have a lot of pages in the root. Otherwise for these small sites it's really not a big deal.

    Its really up to you how it best organizes for yourself you know what I mean?









    For something a bit larger like for a custom application and using Smarty I have my folders a bit different, lots of stuff in the controls.



    I think its really up to the person on how they want to sort things, but if you are concerned about the organization thats fantastic - Good programmers keep things organized. Nobody wants to look through a mess of code and guess where everything is!

    Im just popping this in because of a previous post you had it might not relate now,
    but this is the best way to include a stylesheet because have to change one file for every page it's included on,
    it will pay off later if not now.
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html>
    <head>
    
    <title>Site Here</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <meta name="robots" content="index,follow" />
    <meta name="keywords" content="" />
    
    <link rel="stylesheet" type="text/css" href="css/styles.css" /> 
    
    </head>
    <body>
    
    <?php include('header.php'); ?>
    
    <h1>This page</h1>
    <p>Lots of text.. etc</p>

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Location
    Newcastle Australia
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the book Database Driven Web Site Kevin puts each page in its own directory.

    Just wondering if anyone else uses that method.
    Kevin

  8. #8
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,101
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I always put each page in it's own directory.

    For naming, all "web" files (directories) get named b-inc (a bank of included files) b-images (for images) b-js (JavaScript) etc....

    This way you can easily tell what the pages are and what the web files are.

    Also makes for nice URL's
    What I lack in acuracy I make up for in misteaks

  9. #9
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JREAM,

    You are beautiful!!

    How in the world did you embed screenshots in your post??

    That is soooo helpful!!! (I never you could do that here?!)

    Lots of great information - thanks!!

    I will need to "chew" on all of that for a while, but thanks for the various references!


    Quote Originally Posted by JREAM View Post
    but if you are concerned about the organization thats fantastic - Good programmers keep things organized. Nobody wants to look through a mess of code and guess where everything is!
    Believe it or not, I often start documenting my code before I even write it?!

    I am VERY anal-retentive and demand that things be organized!!


    Im just popping this in because of a previous post you had it might not relate now, but this is the best way to include a stylesheet because have to change one file for every page it's included on,
    it will pay off later if not now.
    Yah, that is one I have to revisit. I know I've started some "wars" on that topic. (Regardless of what people say, it is very hard to come up with "universal" styles... Just look at any major website and they have 20 pages of Style Sheets?! I definitely need to find a way to consolidate my CSS into fewer Classes and IDs)

    Thanks,


    Amy

  10. #10
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amy.damnit View Post
    Okay, I figured things out, and am reminded that I really seem to struggle with determining paths...

    Thanks,

    Amy
    *******************

    Here is where I was getting confused, and it is a "word to the wise" for anyone new to PHP...

    (BTW, how this doesn't trip up other people is beyond me?!)


    Let's say you have these folders and files...

    webroot
    webroot/database
    webroot/includes


    webroot/signin.php
    Code:
      // Include Configuration Settings.
      require_once ('includes/config.inc.php');
    
      // Handle form.
      if (isset($submitted)) {
        
        // Path to DB Connection Script.
        require_once (MYSQL);

    webroot/includes/config.inc.php
    Code:
      define('MYSQL', 'database/seminar_connect.php');

    database/seminar_connect.php
    Code:
    <?php
       DEFINE ('DB_USER', 'username');
       DEFINE ('DB_PASSWORD', 'password');
       DEFINE ('DB_HOST', 'localhost');
       DEFINE ('DB_NAME', 'my_database');
    ?>

    If I am located at webroot/includes/config.inc.php and defining a constant MYSQL you would expect that I would define it RELATIVE TO the file I was in?! (Especially since the file I am in is "included" (i.e. "inherited") and should thus bring over anything that it contains or points to!)

    However, the way it works in PHP - which is totally flaky IMO - is that I define the constant relative to the Parent file that calls it, i.e. database/seminar_connect.php

    This makes no sense to me and has caused me great angst in the past because it goes against the logic of "including" files.


    If "A" includes "B" and "B" references "C", then you would expect "B" to map the path from "C" to itself (i.e. "B"). Then when "A" includes "B", through inheritence, it would "include" and properties and/or references that "B" has.

    That is the way it works in almost any other programming language, and certainly in Object-Oriented Programming (OOP) and in the physical world as well?!

    Having "A" include "B" which refers to "C" which points directly to "A" - bypassing "B" is asinine to say the least?!

    Nobody ever seems to address this strange logic in PHP... (Probably because no one has ever stopped to think it out...)

    So, anyways, I "get it" now, again, after wasting hours last night.

    This time I won't forget this anomaly, but it still irks me!!



    Amy

  11. #11
    SitePoint Zealot
    Join Date
    Oct 2008
    Location
    NE Ohio
    Posts
    117
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KevinChisholm View Post
    In the book Database Driven Web Site Kevin puts each page in its own directory.

    Just wondering if anyone else uses that method.
    When I read this in Kevin's book, I started doing it. I like it. I think his reasoning makes a lot of sense, too.
    William Otis
    Flamenco aficionado and Freelance Web designer
    www.dreammakergraphics.com/

  12. #12
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't totally understand what you're going on about there Amy.D, haha.

    I've never seen anyone do this:
    PHP Code:
    define('MYSQL''database/seminar_connect.php');
    require_once (
    MYSQL
    I guess it's fine but what a strange thing to do haha.
    In my opinion you are making the MySQL connection too complicated.

    Usually people sometimes use what's called a MySQL Wrapper, and it's exactly as it sounds, it wraps around your PHP file (Its included at the top, and all the database calls fit inbetween) and ended at the bottom.

    MySQL Wrappers are usually in the form of an object (or a class file), but you can get by doing it the procedural way just the same.

    Here's an example of what I mean which my be easier for you:

    -- config.inc.php
    PHP Code:
    <?php

        DEFINE 
    ('DB_USER''username');
        
    DEFINE ('DB_PASSWORD''password');
        
    DEFINE ('DB_HOST''localhost');
        
    DEFINE ('DB_NAME''my_database');

        
    $connect mysql_connect(DB_HOSTDB_USERDB_PASS)
            or 
    trigger_error ('Connection Error: ' mysql_error());
            
        
    $database mysql_select_db(DB_NAME)
            or 
    trigger_error ('Database Error: ' mysql_error());
            
       
    ?>
    So wherever config.php is included it will start a database connection, easy peezy with 1 include.

    -- signin.php
    PHP Code:
    // Include Configuration Settings.
    require_once ('includes/config.inc.php');

    // Handle form.
    if (isset($_REQUEST['submitted'])) {
     
        
    // Rest of your stuff, and go through mysql
        
    mysql_query("SELECT * FROM users WHERE id = 1 AND password = 1");
     
    }


    mysql_close($connect); // Optional 
    The last part mysql_close() is optional, I think PHP automatically terminates the connection once the page is completely processed.

  13. #13
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How PHP resolves path isn't strange actually, and you'll find it in the same in most other environments. require(_once)/include(_once)/fopen/anything else that takes a path finds the file relative to the current working directory, not the directory of the initially executed PHP file. You'll find that this applies to the programs that you run on your computer. They too have a working directory. The working directory can also be different from your PHP script's directory too, although in the case of a web server running your PHP file, it won't be.

    If you are on Windows, right click a shortcut to an executable and go to the Shortcut tab. You'll notice the field "Start in" -- that allows you to change the current working directory of the program when you run that shortcut.


Bookmarks

Posting Permissions

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