home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / install / php-switch.php < prev    next >
Encoding:
PHP Script  |  2006-01-20  |  7.8 KB  |  241 lines

  1. <?php
  2.     /*
  3.     #### Installer PHP  1.5  ####
  4.     #### Author: Kay Vogelgesang & Carsten Wiedmann for www.apachefriends.org 2006 ####
  5.     */
  6.  
  7.     echo "\r\n  ########################################################################\n";
  8.     echo "  # ApacheFriends XAMPP PHP Switch win32 Version 1.5                     #\r\n";
  9.     echo "  #----------------------------------------------------------------------#\r\n";
  10.     echo "  # Copyright (c) 2002-2006 Apachefriends                                #\r\n";
  11.     echo "  #----------------------------------------------------------------------#\r\n";
  12.     echo "  # Authors: Kay Vogelgesang <kvo@apachefriends.org>                     #\r\n";
  13.     echo "  #          Carsten Wiedmann <webmaster@wiedmann-online.de>             #\r\n";
  14.     echo "  ########################################################################\r\n\r\n";
  15.  
  16.     ini_set('default_socket_timeout', '3'); // Fix by Wiedmann
  17.     if (false !== ($handle = @fopen('http://127.0.0.1/', 'r'))) {
  18.         fclose($handle);
  19.         echo '   The Apache is running! Please stop the Apache before make this procedure!'."\r\n";
  20.         echo '   Der Apache laeuft gerade! Bitte den Apache fuer diese Prozedur stoppen!'."\r\n";
  21.         echo '   PHP Switch exit ...'."\r\n\r\n";
  22.         exit;
  23.     } else {
  24.         unset($handle);
  25.  
  26.         /// Where I stand? ///
  27.         $curdir = getcwd();
  28.         list($partition, $nonpartition) = split (':', $curdir);
  29.         list($partwampp, $directorwampp) = spliti ('\\\install', $curdir);
  30.         $awkpart = eregi_replace("\\\\", "\\\\", $partwampp);
  31.         $awkpartslash = ereg_replace("\\\\", "/", $partwampp);
  32.         $phpdir = $partwampp;
  33.         $dir = ereg_replace("\\\\", "/", $partwampp);
  34.         $ppartition = "$partition:";
  35.  
  36.         /// I need the install.sys + update.sys for more xampp informations
  37.         $phpversionfile = ".phpversion";
  38.         $phpversionfileroot = $partwampp."\install\\".$phpversionfile;
  39.  
  40.         $phpcurrent = $partwampp."\apache\bin\php.ini";
  41.         $php5safety = $partwampp."\php\php5.ini";
  42.         $php4safety = $partwampp."\php\php4\php4.ini";
  43.         $php4dir = $partwampp."\php\php4";
  44.         $php5dir = $partwampp."\php";
  45.  
  46.         $apachebin = $partwampp."\apache\bin";
  47.         $httpconf = $partwampp."\apache\conf\extra\httpd-xampp.conf";
  48.  
  49.         /// XAMPP main directrory is ...
  50.         $substit = "\\\\\\\\xampp";
  51.         $substitslash = "/xampp";
  52.  
  53.         /// Globale variables
  54.         $BS = 0;
  55.         $CS = 0;
  56.  
  57.         $awkexe = ".\install\awk.exe";
  58.         $awk = ".\install\config.awk";
  59.  
  60.         $awknewdir = "\"".$awkpart."\"";
  61.         $awkslashdir = "\"".$awkpartslash."\"";
  62.  
  63.         if (file_exists($phpversionfileroot)) {
  64.             $datei = fopen($phpversionfileroot, 'r');
  65.             while (!feof($datei)) {
  66.                 $phpcurrentv = fgets($datei, 255);
  67.             }
  68.             fclose($datei);
  69.         } else {
  70.             echo "   Cannot find $phpversionfileroot! So i cannot select the current PHP version.\r\n";
  71.             echo "   Die $phpversionfileroot! Kann nicht die akuelle PHP Version bestimmen.\r\n";
  72.             echo "   PHP Switch exit ...\r\n\r\n";
  73.             exit;
  74.         }
  75.  
  76.         if (($phpcurrentv != "4") && ($phpcurrentv != "5")) {
  77.             echo "   The PHP version number is not valid.\r\n";
  78.             echo "   Die PHP Version Nummer ist ungueltig.\r\n";
  79.             echo "   PHP Switch exit ...\r\n\r\n";
  80.             exit;
  81.         }
  82.  
  83.         echo "\r\n\r\n  The working version in XAMPP is => PHP $phpcurrentv <=\r\n";
  84.         echo "  The verwendete Version in XAMPP ist => PHP $phpcurrentv <=\r\n\r\n";
  85.  
  86.         set_time_limit(0);
  87.         define('NEWSTDIN', fopen("php://stdin", "r"));
  88.         while ($CS == "0") {
  89.             echo "\r\n  Type number or 'x' (exit) for selecting your choice!\r\n";
  90.             echo "  Gebe nun Nummer oder 'x' (exit) zum auswaehlen ein!\r\n\r\n";
  91.             if ($phpcurrentv == "5") {
  92.                 echo "  4) Switching to PHP 4 (zu PHP 4 wechseln)\r\n";
  93.             } elseif ($phpcurrentv == "4") {
  94.                 echo "  5) Switching to PHP 5 (zu PHP 5 wechseln)\r\n";
  95.             } else {
  96.                 echo "  5) Switching to PHP 5 (zu PHP 5 wechseln)\r\n";
  97.                 echo "  4) Switching to PHP 4 (zu PHP 4 wechseln)\r\n";
  98.             }
  99.             echo "  x) Exit (Beenden)\r\n";
  100.  
  101.             switch (trim(fgets(NEWSTDIN, 256))) {
  102.                 case 4:
  103.                     $CS = 4;
  104.                     echo "\r\n  Starting configure XAMPP with PHP 4 ...\r\n\r\n";
  105.                     sleep(1);
  106.                     break;
  107.  
  108.                 case 5:
  109.                     $CS = 5;
  110.                     echo "\r\n  Starting configure XAMPP with PHP 5 ...\r\n\r\n";
  111.                     sleep(1);
  112.                     break;
  113.  
  114.                 case "x":
  115.                     echo "\r\n  PHP Switch is terminating on demand ...  exit\r\n";
  116.                     echo "  PHP Switch wurde auf Wunsch abgebrochen ...\r\n\r\n";
  117.                     sleep(3);
  118.                     exit;
  119.  
  120.                 default:
  121.                     exit;
  122.             }
  123.         }
  124.         fclose(NEWSTDIN);
  125.  
  126.         if (($CS == "4") && ($phpcurrentv=="5")) {
  127.             echo "  Installing PHP4 in XAMPP now!\r\n\r\n";
  128.             sleep(1);
  129.  
  130.             if (file_exists($phpcurrent)) {
  131.                 echo "  Copy the current php.ini to $php5safety ... ";
  132.                 copy($phpcurrent, $php5safety);
  133.                 echo "done!\r\n";
  134.             }
  135.  
  136.             if (file_exists($php4safety)) {
  137.                 echo "  Copy the php4.ini to $phpcurrent ... ";
  138.                 copy($php4safety, $phpcurrent);
  139.                 echo "done!\r\n\r\n";
  140.             }
  141.  
  142.             if (file_exists($httpconf)) { // Fix by Wiedmann
  143.                 echo '  Change PHP settings in '.$httpconf.' ... ';
  144.                 $httpconfcontent = file_get_contents($httpconf);
  145.                 $httpconfcontent = strtr($httpconfcontent,
  146.                     array(
  147.                         'php5_module' => 'php4_module',
  148.                         'php5ts.dll' => 'php4ts.dll',
  149.                         'php5apache2.dll' => 'php4apache2.dll',
  150.                         '/php/php-cgi.exe' => '/php/php.exe',
  151.                         '/xampp/php/' => '/xampp/php/php4/'
  152.                     )
  153.                 );
  154.                 file_put_contents($httpconf, $httpconfcontent);
  155.                 echo 'done!'."\r\n\r\n";
  156.             }
  157.  
  158.             echo "  Copy now all php4 dlls to $apachebin\r\n\r\n";
  159.  
  160.             $dh = opendir($php4dir);
  161.             while ($file = readdir($dh)) {
  162.                 if (eregi("(\.dll|\.jar)", $file)) { // Fix by Wiedmann
  163.                     $php4file = $partwampp."\php\php4\\".$file;
  164.                     $phpcpfile = $partwampp."\apache\bin\\".$file;
  165.                     if (file_exists($phpcpfile)) {
  166.                         copy($php4file, $phpcpfile);
  167.                         echo "$php4file => $phpcpfile\r\n";
  168.                     }
  169.                 }
  170.             }
  171.             closedir($dh);
  172.  
  173.             echo "  Write the new PHP main version in $phpversionfileroot\r\n";
  174.             $datei = fopen($phpversionfileroot, 'w');
  175.             fputs($datei, "4");
  176.             fclose($datei);
  177.         }
  178.  
  179.         if (($CS == "5") && ($phpcurrentv == "4")) {
  180.             echo "  Installing PHP5 in XAMPP now!\r\n\r\n";
  181.             sleep(1);
  182.  
  183.             if (file_exists($phpcurrent)) {
  184.                 echo "  Copy the current php.ini to $php4safety ... ";
  185.                 copy($phpcurrent, $php4safety);
  186.                 echo "done!\r\n";
  187.             }
  188.  
  189.             if (file_exists($php5safety)) {
  190.                 echo "  Copy the php5.ini to $phpcurrent ... ";
  191.                 copy($php5safety, $phpcurrent);
  192.                 echo "done!\r\n\r\n";
  193.             }
  194.  
  195.             if (file_exists($httpconf)) { // Fix by Wiedmann
  196.                 echo '  Change PHP settings in '.$httpconf.' ... ';
  197.                 $httpconfcontent = file_get_contents($httpconf);
  198.                 $httpconfcontent = strtr($httpconfcontent,
  199.                     array(
  200.                         'php4_module' => 'php5_module',
  201.                         'php4ts.dll' => 'php5ts.dll',
  202.                         'php4apache2.dll' => 'php5apache2.dll',
  203.                         '/php/php.exe' => '/php/php-cgi.exe',
  204.                         '/xampp/php/php4/' => '/xampp/php/'
  205.                     )
  206.                 );
  207.                 file_put_contents($httpconf, $httpconfcontent);
  208.                 echo 'done!'."\r\n\r\n";
  209.             }
  210.  
  211.             echo "  Copy now all php5 dlls to $apachebin\r\n\r\n";
  212.  
  213.             $dh = opendir($php5dir);
  214.             while ($file = readdir($dh)) {
  215.                 if (eregi("(\.dll|\.jar)", $file)) { // Fix by Wiedmann
  216.                     $php5file = $partwampp."\php\\".$file;
  217.                     $phpcpfile = $partwampp."\apache\bin\\".$file;
  218.                     if (file_exists($phpcpfile)) {
  219.                         copy($php5file, $phpcpfile);
  220.                         echo "$php5file => $phpcpfile\r\n";
  221.                     }
  222.                 }
  223.             }
  224.             closedir($dh);
  225.  
  226.             echo "  Write the new PHP main version in $phpversionfileroot\r\n";
  227.             $datei = fopen($phpversionfileroot, 'w');
  228.             fputs($datei, "5");
  229.             fclose($datei);
  230.         }
  231.  
  232.         echo "\r\n  OKAY ... PHP SWITCHING WAS SUCCESSFUL";
  233.         echo "\r\n\r\n  Now you can start the Apache with PHP $CS !";
  234.         echo "\r\n  Nun kannst du den Apache mit PHP $CS starten!";
  235.         sleep(1);
  236.  
  237.         echo "\r\n\r\n  :-) Kay Vogelgesang & Carsten Wiedmann (www.apachefriends.org)\r\n\r\n";
  238.         exit;
  239.     }
  240. ?>
  241.