Jump to content

Includes or full code in one page?


BluRay

Recommended Posts

Hey guys,

I'm starting to build my own website from scratch but first, I would need to get some answers to my questions.

 

I've noticed that some websites are built and divided "parts". Let me explain what I mean.

 

<?php
  include('header.php');
  include('left-side.php');
  include('right-side.php');
  include('footer.php');
?>

 

I personally think it would be easier if I want to create more pages. e.g a register page. In this case I would just do this:

 

<?php

  include('header.php'); // should include be require in this case, right?
  include('left-side.php');
  include('right-side.php');
  include('footer.php');

  // start of register script
  echo '<form action="registered.php" method="post">
     ID: <input type="text" name="id" />
     PW: <input type="text" name="pw" />
         <input type="submit" />
        </form>';
  //end of register script

?>

 

Or do you think this is not the right way I should start building my site? If you need some explanation, let me know.

 

Thank in advance.

Link to comment
https://forums.phpfreaks.com/topic/206440-includes-or-full-code-in-one-page/
Share on other sites

I guess, its all up to you... I like to include things to make it a bit more organized for me when im coding a big site...

 

When i'm including pages ill do something on the index like:

include(header.php);
if($_GET['page']){
if(!file_exists($page . '.php')){
$page = "error";
}else{
$page = $_GET['page'];
}
}else{
$page = "homepage.php";
}
include($page.'.php'); 
include(footer.php);

having it set homepage.php the default if no user is going to a page (index.php?page=pagename)...

 

another reason i like if it happens (knock on wood) i'll get hacked (injected or what not) or what not they usually will just change the index.php being its the main file.. and i wont loose the whole template just the simple php that was including the important parts of the site. get me?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.