• Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

PHP...how does it work for websites?

Purin

Crazy about Pink Hairdos
  • 2,193
    Posts
    21
    Years
    I've tried finding guides for this on the internet and books in the library, but the way they teach it isn't beginner-friendly IMO.
    I'm thinking of changing one of my website's layout to include this, since frames don't look good on the current layout.
     
    All depends on what you want to do..

    basic includes abd be done a couple of ways.. including header / footer info onto your content pages i.e. links to: page1.php, page2.php, etc.. or you can include content into a index (layout) page i.e. links look like: index.php?page=page1, index.php?id=dir/page, etc...

    Then you can do active page generation using templates and other files (like how PC does it) It's all HOW you want to do it.
    Basic content include code:
    PHP:
    // Nav and static content: 
    <?php include ('path/to/file.ext'); ?>
    
    // Content Pages code: 
    // (this will include pagename.html into your index or layout page)
    <?php
    if (!$id) {
    $id = "main";
    $include = $id . ".html";
    }
    else {
    $include = $id . ".html";
    }
    if (is_file($include) == "1") {
            include $include;
    }
    else {
    include "404.html";
    }
    ?>
    All you do is create your layout / index.php, and where your content goes, you place the content page code. your main or home page should be named main.html The 404.html page is a generic '404 - can not find the page' error page incase of link errors and can also be set (using .htaccess) as your overall 404 page. If you want your nav links to be included then you reomve then from index page, then save them as nav.inc (or .txt, or .html, etc.. ) and use the static include code. You can see it's a lot like ssi and is so much cleaner then frames.
     
    Last edited:
    Well, there are a couple ways... I'll show you two of 'em. And I'm assuming your friend is using a typical 3 column site with tables.


    Code:
    You can do it in a way where there are two different layout pages.  In "layout1.php" you would write something like...
    
    <html>
    <head>
    <title>Blue Bar</title>
    </head>
    <body>
    <table width="100%">
    <tr><td width="100%" colspan="3"><center>BANNER</center></td></tr> <!-- That's the banner -->
    <tr>
    <td width="15%">Everything in the first column would go here.</td>
    <td width="70%">
    
    And that's layout1.php.  Then you make layout2.php
    
    </td>
    <td width="15%">You'd put the right column stuff in here.</td>
    </tr>
    <tr><td colspan="3">Put a footer here</td></tr>
    </table>
    </body>
    </html>
    
    Save it.
    
    Now, for each page of content, the page should look similar to this
    <html>
    <head>
    <title>Blue Bar</title>
    </head>
    <body>
    <? include("layout1.php") ?>
    Everything in the main section of the page goes here.  Content, everything.
    <? include("layout2.php") ?>
    </body>
    </html>
    
    
    And there you have it, a page where the layout can be editted simply by changing 1 (or 2) pages, and not every single page.  And it doesn't look funny, like the frames.  :P


    Code:
    Now, there is another way I know of.  Though, it's a tad more tricky... you just have one layout file...
    <html>
    <head>
    <title>Blue Bar</title>
    </head>
    <body>
    <table width="100%">
    <tr><td colspan="3"><center>BANNER</center></td></tr>
    <tr>
    <td width="15%">Left column stuff.</td>
    <td width="70%"><? print("$content") ?></td>
    <td width="15%">Right column stuff.</td>
    </tr>
    <tr><Td>Footer</td></tr>
    </table>
    
    Save that as layout.php...
    
    Then for each content page, you have to do it like this...
    
    <html>
    <title>Blue Bar</title>
    <body>
    <? 
    $content = "Whatever you want in the content.  You can [b]not[/b] use double quotes in here.  For changing fonts, etc, you have to use single quotes like... <font color='blue'>Blue font</font>" ;
    //Make sure you add that ending quote and the ";"!!!
    
    include("layout1.php");
    ?>
    </body>
    </html>
    
    Then save that as whatever.  That was, when you go to yousite.com/content.php, it will read what the variable is (you defined the $content variable by doing the $content = "X") and then print it after it loads the layout.  It doesn't work if you include the layout first, as it prints it without knowing what $content is, so it leaves a blank space.


    And that's all I have to say... hope that was some help!
     
    PHP, although the say it's a simple language to learn, does confuse a lot of people at first.

    So don't feel bad. :P
     
    JKaizer said:
    PHP, although the say it's a simple language to learn, does confuse a lot of people at first.

    So don't feel bad. :P
    The guides from you and PPNSteve look useful (they might be), so I'll save them down to read and compare with this library book that I borrow (which isn't of much use, from what I think).
    Once I've learned it, I might try my hands on making a guide that will be simple to understand for beginners with at least some HTML knowledge.
     
    what we've shown you is very basic and basiclly replaces SSI and/or frames..
    it's easy to convert existing pages (framed or ssi) using these codes.. (great if you have lots of existing pages)

    But php is far more usable in generating active pages, preforming funtions, etc... and you really should read a few books and maybe do a search for tutorials on the web, just to help you understand those overly complex books.
     
    *link removed* theres a guide i helped write for php includes
     
    SSI is an older way of doing the functions that php does. At least that's what I think...
     
    Purin said:
    pokemon706: I've already got a host for that website. Thanks for the offer anyway.
    What's the difference between SSI and PHP?
    For SSI, what you will need is a right column layout page and a left column layout page. Then you put in include into where you want the right and columns on the content page. That's all I know about SSI.
    If you want to extened you knowledge of PHP, I recomend https://www.w3schools.com.
     
    Oh, I see, I've been wanting to know how to do that for ages! I'll do my Physics project using that XD
     
    SSI is server side includes, its got the extension .shtml like Serebii.net or mewshangout.net.

    Using PHP is a much more useful and easier way to make a website. Because alot of newspros, cutenews, fusion news use PHP, they need a php page to run properly.

    Also, I cna probably host you if you ever need a server. But i don't do free hosting usally, i just see potencial in your site. (don't worry i have my own server ,its fast enough lol.)
     
    Simone said:
    SSI is server side includes, its got the extension .shtml like Serebii.net or mewshangout.net.

    Using PHP is a much more useful and easier way to make a website. Because alot of newspros, cutenews, fusion news use PHP, they need a php page to run properly.

    Also, I cna probably host you if you ever need a server. But i don't do free hosting usally, i just see potencial in your site. (don't worry i have my own server ,its fast enough lol.)

    Coranto at least does not need a php page to run, works just fine on my shtml page.
     
    Last edited:
    WEll I guess some might work on an shtml page, but meh. Most won't.
     
    Back
    Top