Here's an example of this transformational logic.
Start with this program, to reinforce our knowledge of sessions:
<? session_start();
if ($message){
$num+=1;
} else {
$message = "This is my program";
session_register ("message");
$num = -3;
session_register ("num");
}
?>
The number is : <? echo $num ?> <p>
Click <a href = " " >here</a> to add 1 to the number.
We then changed it to client-side state:
<?
if ($message){
$num+=1;
} else {
$message = "This is my program";
$num = -3;
}
?>
The number is : <? echo $num ?> <p>
Click <a href = "?num=<?=$num ?>&message=<?= $message?> " >here</a> to add 1 to the number.
We then converted this last program to CGI with client-side state:
#!/usr/bin/perl
use CGI;
$q = new CGI;
$message=$q->param('message');
$num=$q->param('num');
print $q->header, $q->start_html;
if ($message){
$num+=1;
} else {
$message = "This is my program";
$num = -3;
}
print qq {
The number is : $num <p>
Click <a href = "?num=$num&message=$message " >here</a> to add 1 to the
number.
};
print $q->end_html;
You see that the logic inside does not change at all.