Salve, sto realizzando il mio primo e vero script in PHP, è uno script semplice però ho trovato 2 ostacoli che ho provato in tutti i modi di risolvere, il mio primo problema è nelle sessioni, praticamente una volta effettuato il login si può accedere al index.php?p=main, però se modifico direttamente l'url in alto mi accede, non capisco dove sia il problema, il secondo è quando riporto un errore o una conferma il codice esce dal container e visualizzo sempre il form, come mai succede questo? Soluzioni?
Codice PHP:
<?php
/*
 ________________________________________________
/                                               /|
################################################ |
#   ========================================   # |
#   Random Items                               # |
#   ========================================   # |
#   by FF Report                               # |
#   (c) 2012 - 2013                            # |
#   ========================================   # |
#   [url]http://ffreport.forumcommunity.net/[/url]        # |
#   ========================================   # | 
################################################/

*/

// Riporto ogni errore
error_reporting(E_ALL);

// Definisco la directory per l'upload
define('UPLOAD_DIR''images/');

function 
display_layout($layout_name) {
    
$layout "layout_" .$layout_name;
    if (
function_exists($layout)) {
        
layout_header();
        
$layout();
        
layout_footer();
        
    }
}
###################
##    LAYOUTS    ##
###################

/**
 * Layout => Header
 */
function layout_header() {
    echo 
"<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
        <title>Random Items</title>
        <style>
            body {
                background: #1B2D2E;
                font-family: \"Segoe UI\";
                color: #D16531;
                text-shadow: 0px 0.5px 0.5px #822107;
            }
            
            a {
                color: #D16531;
                text-decoration: none; 
                -webkit-transition: all 0.3s ease; 
                -moz-transition: all 0.3s ease
            }
            a:hover {
                color: #822107;
                text-decoration: none; 
                -webkit-transition: all 0.3s ease; 
                -moz-transition: all 0.3s ease
            }
            
            #container {
                width: 500px;
                height: auto;
                margin: auto;
                margin-top: 50px;
                padding: 0.5px 50px 5px 50px;
                background: #FFFCFA;
                border-radius: 10px;
                box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5);
            }
            
        </style>
    </head>
    <body>
        <div id=\"container\">"
;
}
    
/**
 * Layout => Footer
 */
function layout_footer() {
    echo 
"        
            </div>     
        </body>
    </html>"
;
}

/**
 * Layout => Install
 */
function layout_install() {
    if(
file_exists("data.php")) {
        
layout_login();
    }
    else {
        echo
"<h3 align=\"center\">Random Items</h3>
            <h3>Installazione</h3>
            <form action=\"index.php\" method=\"post\">
            Password <input type=\"password\" name=\"password\">
            <input type=\"submit\" value=\"Installa\">
            </form>"
;
    }
}

/**
 * Layout => Login
 */
function layout_login() {
    echo
"<h3 align=\"center\">Random Items</h3>
            <h3>Login</h3>
            <form action=\"index.php?p=login\" method=\"post\">
            Password <input type=\"password\" name=\"controll\">
            <input type=\"submit\" value=\"Login!\">
            </form>"
;
}

/**
 * Layout => Main
 */
function layout_main() {
    echo 
"<h3 align=\"center\">Random Items</h3><div style=\"text-align: center; word-spacing: 20px;\"><a href=\"?p=home\">Home</a> <a href=\"?p=links\">Links</a> <a href=\"http://ffreport.forumcommunity.net/\">FFReport</a></div>";
}
###################
##   FUNCTIONS   ##
###################

/**
 * Function => Install
 */
function install() {
    
$password $_POST['password'];
    
    if (!empty(
$password)) {
        
$contents "<?php return array('controll' => $password)?>";
        
file_put_contents ('data.php'$contents);
        echo 
"<div class=\"info\">Il Random Items è stato installato correttamente tra poco verrai reindirizzato al menù principale per effettuare il login.</div>";
        
header("Refresh: 3; index.php");
    }
    
display_layout('install');
}

/**
 * Function => Login
 */
function login() {
    
$controll $_POST['controll'];
    
$data = require("data.php");
    
    if (
$data['controll'] == $controll) {
        
session_start();
        
$_SESSION['login'] = "ok";
        echo 
"<div class=\"info\">Login effettuato con successo, sarai reindirizzato al menù principale.</div>";
        
header('Refresh: 3; index.php?p=main');
        }
    else {
        echo 
"<div class=\"alert\">Login errato.</div>";
    }
    
display_layout('login');
}

/**
 * Function => Main
 */
function main() {
    
session_start();
    
    if (
$_SESSION['login'] == "ok") {
        
        
    }
    else {
        echo 
"<div class=\"alert\">Non hai effettuato il login!</div>";
        
header('Refresh: 3; index.php');
    }
    
display_layout('main');
}
$page = (isset($_GET['p'])) ? (string) $_GET['p'] : '';

        switch (
$page)
        {
            case 
'main':
                
main();
            break;

            case 
'login':
                
login();
            break;
            case 
'install':
                
install();
            default:
                
install();
}    
?>