header image
 

[Guida] Creare un sito dinamico in PHP

V3rgil, vergil666_dmc@yahoo.it, http://gr4h4m.wordpress.com

[DoWnLoAd]

Un modo che trovo simpatico per produrre siti web è quello del template tramite php.
Richiamando le pagine del template e usando funzioni si può tranquillamente creare un sito web.
Ecco di seguito come fare un sito semplice semplice:

Pagine Index:

Codice:

<?
/* Includiamo le pagine per le funzioni */
require(”functions.php”);
require(”template/top.php”);
require(”template/body.php”);
require(”template/foot.php”);
/* Fine includimento */
$title = “Home Page”;/* Definiamo titolo pagina */
top($title);/* Funzione di apertura codice */
menu();/* Richiamo del menu */
top2();/* Chiusura struttura logo */
body();/* Richiamo funzione body(corpo pagina) */
?>
/* CONTENUTO PAGINA */
<?
body2();/* Richiamo funzione chiusura body(fine corpo pagina) */
news();/* L’ho chiamato news ma si può usare come menu laterale o per banner e simili(struttura verticale) */
body3();/* Chiusura struttura generale */
foot();/* Chiusura codice con pagina footer */
?>
Codice Function:

Codice:

<?
function menu () {
?>
/* NON MODIFICARE I TR E I TD SE NON SI HANNO CONOSCENZE BASI DEL LINGUAGGIO HTML */
/* Nel caso di un menu diverso modificare il contenuto della funzione “top();” */
<tr>
<td><a href=”index.php”><img src=icona.jpg>Home Page</a></font></td>
<td><a href=”contents.php”><img src=icona.jpg>Pagina 1</font></a></td>
<td><a href=”contents.php?id=2″><img src=icona.jpg>Pagina 2</font></a></td>
</tr>
<tr>
<td><a href=”contents.php?id=3″><img src=icona.jpg>Pagina 3</font></a></td>
<td><a href=”contents.php?id=4″><img src=icona.jpg>Pagina 4</font></a></td>
<td><a href=”directoryforum/”><img src=icona.jpg>Forum</font></a></td>
</tr>
<?
}

function news () {
?>
/* Consiglio di strutturare questo blocco con una tabella per renderlo graficamente migliore */
<?
}
?>
Codice Contents:

Codice:

<?
/* A SECONDA DELL'ID DELLA PAGINA CAMBIA IL TITOLO */
/* IL TITOLO DI DEFAULT E' QUELLO DELLA PRIMA PAGINA */
$_GET['id'] = isset($_GET['id']) ? $_GET['id'] : ”;

switch ($_GET['id']) {
case “1″:
$title = “Pagina 1″;
break;

case “2″:
$title = “Pagina 2″;
break;

case “3″:
$title = “Pagina 3″;
break;

case “4″:
$title = “Pagina 4″;
break;

case “”:
$_GET['id'] = 1;
$title = “Pagina 1″;
break;

}
require(”functions.php”);
require(”template/top.php”);
require(”template/body.php”);
require(”template/foot.php”);
top($title);
menu();
top2();
body();

switch ($_GET['id']) {
case “1″:
?>
/* CONTENUTO PAGINA 1 */
<?
break;

case “2″:
?>
/* CONTENUTO PAGINA 2 */
<?
break;

case “3″:
?>
/* CONTENUTO PAGINA 3 */
<?
break;

case “4″:
?>
/* CONTENUTO PAGINA 4 */
<?
break;

}

body2();
news();
body3();
foot();
?>

Passiamo alle pagine che formano il template, sono 3 pagine top.php body.php e foot.php e all’interno contengono le rispettive funzioni per la creazione della grafica.
Di seguito il codice di ogni pagina:

Codice Top:

Codice:

<?
function top ($title) {
?>
<html>
<head>
<LINK REL=”SHORTCUT ICON” href= “favicon.ico”>/* MEGLIO SPECIFICARE L’ESATTA URL DEL SITO */
<title>Nome Sito - <? echo $title; ?></title>
<link rel=”stylesheet” type=”text/css” href=”template/sito.css”>

</head>
<body background=”/immagini/bg.gif” bgproperties=”fixed”>
<table width=100%>
/*
TOGLIERE I SENGI DI COMMENTO PER ABILITARE IL BORDO DAL LOGO, PER BORDO SI INTENDO BORDI GRAFICI COMPOSTI DA IMMAGINI
NEL CASO SI METTANO IMPOSTARE L’ALTEZZA DESIDERATA NEL TAG SEGUENTE
<tr>
<td colspan=2 width=100% height=23 background=”/immagini/back.JPG”></td>
</tr>
*/
<tr>
<td><center><img src=”/immagini/logosito.bmp”></center></td>
<td background=”/immagini/bgcorpo.bmp”>
<table>
<?
}

function top2 (){
?></table>
</td>
</tr>
/*
TOGLIERE I SENGI DI COMMENTO PER ABILITARE IL BORDO DAL LOGO, PER BORDO SI INTENDO BORDI GRAFICI COMPOSTI DA IMMAGINI
NEL CASO SI METTANO IMPOSTARE L’ALTEZZA DESIDERATA NEL TAG SEGUENTE
<tr>
<td colspan=2 width=100% height=20 background=”/immagini/back.JPG”></td>
</tr>
*/
<?
}
?>
Codice Body:

Codice:

<?
function body()
{
?>
<tr>
<td colspan=2><center>
<br><br>
<center>
<table width=90% height=500 cellpadding=”10″ cellspacing=”2″>
<left>
<tr>
<td valign=top background=”http://giornalinoactive.altervista.org/immagini/corpo.bmp”>
<?
}

function body2()
{
?>
</td>
<td width=15% valign=top background=”http://giornalinoactive.altervista.org/immagini/corpo.bmp”>
<table>
<?
}

function body3()
{
?>
<table>
</td>
</tr>
</left>
</table>
</center>
</center></td></tr>
</table>
<?
}
?>
Codice Foot:

Codice:

<?
/* CHIUSURA CODICE HTML */
function foot()
{
?>
</body>
</html>
<?
}
?>

ecco inseriti tutti il codice per far funzionare questo mini sito dinamico, non dimenticatevi di inserire la css per la grafica.
Se servisse posso anche postare quella di default con i gusti miei personali.
Scrivo di seguito la strutturazione del sito web:

/index.php
/functions.php
/contents.php
/template/top.php
/template/body.php
/template/foot.php
/template/sito.css
/immagini/bgcorpo.bmp
/immagini/back.JPG
/immagini/logosito.bmp

Per dubbi o chiarimenti sulla funzionalità postare di seguito.
Spero vi possa essere utile.
Ciauz

P.S.: Nel caso di trasporto della guida è esplicitamente richiesto di includere la fonte e l’autore, non sono presenti altre restrizioni sull’uso del codice.

 
   
 
 

~ di gr4h4m su Dicembre 17, 2007.

2 Risposte to “[Guida] Creare un sito dinamico in PHP”

  1. ciao forte sta roba puoi postarmi la tua css grazie

  2. Ciao, sto iniziando a “strusare” con php e volevo sapere se potevo contare su di te per delle nozioni o domande varie. Grazie

Lascia una Risposta