Visualizzare un sorgente PHP via web

From RVM Wiki
Revision as of 13:19, 27 December 2006 by Gabriele.vivinetto (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

E' possibile visualizzare il sorgente di un file php con la syntax highlighting, in due modi:

  1. Copiare il file .php in .phps e visualizzarlo nel browser. Se il webserver è Apache (2), verrà mostrato il source, a colori.
  1. Usare questo script: http://www.zend.com/codex.php?id=203&single=1
<?

/******************************************
#  File:  view_source.php
#  Description: Script to view code with highligths.
#                Link to this file with 
#                "view_source.php?source=/mypath/myfile.php"
#                
#                Makes a copy of the php file and names it phps.
#                And then redirects the browser to the new phps file.
#                phps files are automaticly code highlighted and displayed
#                if you are using Apache.
#
#  Author: Krister Konst
#          krister@krikon.com
******************************************/








function source($source) 
{  
  clearstatcache();                              // cache of the filething dele. 
  if(!file_exists($source))                      // Checking for the file $source. 
  { 
    return false; 
  } 
  


// this returns an array of string of wich the last element is the filename.
$path_array= split("/" , $source);

$num = sizeof($path_array);
$str = str_replace ("php", "phps", $path_array[$num-1]);


global $target_file

// to make this work you must make the source directory first. 
$target_file = "./source/" . $str;

 copy($source,$target_file);

      
  return true; 

} 

source($source);

header ("Location: $target_file");                 /* Redirect browser 
                                           to the newly created phps file/
exit;                 /* Make sure that code below does 
                         not get executed when we redirect. */
      




?>