<? Php
Function CreateShtml ()
{
Ob_start (array ("callback_CreateShtml", "callback_GoToShtml "));
}
Function callback_CreateShtml ($ buffer )[
{
$ Page = intval (@ $ _ REQUEST ["page"]);
$ FileName = $ _ SERVER ['document _ root']. dirname ($ _ SERVER ['php _ SELF ']). "/". basename ($ _ SERVER ['php _ SELF '], ". php "). ($ page = 0? "": "_". Strval ($ page). ". htm ";
$ Fp = fopen ($ fileName, "wb ");
Fwrite ($ fp, $ buffer );
Fclose ($ fp );
Return $ buffer;
}
Function callback_GoToShtml ($ buffer)
{
$ Page = intval (@ $ _ REQUEST ["page"]);
$ FileName = basename ($ _ SERVER ['php _ SELF '], ". PHP"). ($ page = 0? "": "_". Strval ($ page). ". htm ";
Header ("location:". $ fileName );
Return $ buffer;
}
Function GoToShtml ()
{
$ Page = intval (@ $ _ REQUEST ["page"]);
$ FileName = basename ($ _ SERVER ['php _ SELF '], ". PHP"). ($ page = 0? "": "_". Strval ($ page). ". htm ";
If (file_exists ($ fileName ))
Header ("location:". $ fileName );
}
Function DeleteShtml ($ fileName = NULL)
{
If (is_null ($ fileName ))
$ FileName = $ _ SERVER ['document _ root']. $ _ SERVER ['php _ SELF '];
If ($ fileName [0] = "/")
$ FileName = $ _ SERVER ['document _ root']. $ fileName;
$ Path = dirname ($ fileName );
$ Dir = dir ($ path );
$ Patten = "/^". basename ($ fileName, ". php"). "(_ [0-9] + )?. Htm /";
While ($ entry = $ dir-> read ())! = False)
{
If (is_file ($ path. "/". $ entry) & preg_match ($ patten, $ entry ))
Unlink ($ path. "/". $ entry );
}
}
CreateShtml ();
Echo "this is a static page! $ Page ";
GoToShtml ();
DeleteShtml ();
?>