PHP Cookbook for CGI
Introduction
     A la différence du PERL ou du C, le PHP ne cherche pas à générer du code HTML à travers le serveur, mais à y exécuter directement des actions. Il permet non seulement de générer des pages web dynamiquement (CGI) mais aussi de gérer les bases de données ou utiliser des protocoles (IMAP, POP3, ...).
     Pour plus d'infos, en particulier comment installer un serveur PHP/Apache, il me semble essentiel de consulter le très bon site http://www.php.net/ qui vous racontera tout. La suite de ce chapitre ne fait référence qu'à certains points essentiels du langage.
     Contrary to PERL or C languages, the aim of PHP is not to generate some HTML code through the server, but to execute actions directly on it. It allows not only to generate dynamic HTML pages (CGI) but also to manage databases and different protocols (IMAP, POP3, ...).
     For further information, particularly how to install a PHP/Apache server, I think it's necessary to have a look to the very good website http://www.php.net/ which will tell you everything. The following chapters just relate some important notions of this language.


You can download a Apache/MySQL/PHP WebServer for Windows at : http://www.easyphp.org/ (10.5 Mo)
Basic Structure
<HTML>
  <HEAD>
    <TITLE>The title of the page</TITLE>
  </HEAD>
  <BODY>
    <?php
      The PHP code itself
    ?>
  </BODY>
</HTML>
Mix HTML and PHP
<?php if ( boolean-expression ) { ?>
  <strong>This is true.</strong>
<?php } else { ?>
  <strong>This is false.</strong>
<?php } ?>
Example of POST method using my ALLHTML lib
- The POST method is the formulary submission method. Variables can be obtained by $var=$_POST["var"].
- The GET method is the url submission method. Variables can be obtained by $var=$_GET["var"].

For convenience of designing mixed PHP-HTML code, I developped a PHP library - The hlib - which implements and simplifies HTML basic tags. It also manage code indentation and GET/POST variables (forms).

An example for formulary with checkboxes, list, text, image, links and button :
'Check it' is unchecked
'Uncheck it' is checked
'Select it' =
'Text it' =
'imageit' =
'urlvalueit' =
           Check it
Uncheck it
Select it
Text it

Lien 1     Lien 2

<SCRIPT language="JavaScript" type="text/javascript">
<!--
function submiturl ( urlvalue )
{
  document.formit.urlvalueit.value = urlvalue ;
  document.formit.submit() ;
}
-->
</SCRIPT>

<?PHP
  if ((!isset($forminit))&&(!isset($checkit))) $checkit=0;
  if ((!isset($forminit))&&(!isset($uncheckit))) $uncheckit=1;

  if ($checkit) hecho("'Check it' checked"); else hecho("'Check it' unchecked"); hbr();
  if ($uncheckit) hecho("'Uncheck it' checked"); else hecho("'Uncheck it' unchecked"); hbr();
  hecho("'Select it' = ".$selectit); hbr();
  hecho("'Text it' = ".$textit); hbr();
  hecho("'imageit' = ".$imageit); hbr();
  hecho("'urlvalueit' = ".$urlvalueit); hbr(2);

  hformd(NULL,"formit"); hhidden("forminit",1);
  hcheckbox("checkit",$checkit); hecho(" Check it"); hbr();
  hcheckbox("uncheckit",$uncheckit); hecho(" Uncheck it"); hbr();
  hecho("Select it "); hselectd("selectit"); hoption("Option A",1); hoption("Option B",2); hselectf(); hbr();
  hecho("Text it "); htextline(NULL,0,"textit",NULL,NULL,$textit); hbr();
  himage("imageit","zeimage","img","img.jpg"); hbr();
  hhidden("urlvalueit");
  ha("javascript:submiturl('1');","Lien 1"); hbr();
  ha("javascript:submiturl('2');","Lien 2"); hbr();
  hbutton(NULL,); hbr();
  hformf();
?>
 [Menu]
Last Update
10/12/2018
32719 visitors
850589 robots
since 01/01/2003
Page generated
in 0.66 second
💗 2003-2018 by S. MARLIERE. Copying is an act of love. Love is not subject to law. Please copy and share.