Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.70 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. if (!(is_writable('config.php')))//controllo se il file config.php รจ scrivibile
  6.     die("<em>Settare i permessi del file config.php a 777 (chmod)</em>");
  7.    
  8. if(!(file_exists('config.php'))) // controllo se il file config.php esiste
  9.     die("<em>File 'config.php' inesistente| Creare un file chiamato config.php vuoto</em>");
  10.  
  11. ?>
  12.  
  13. <html>
  14. <head>
  15. <title>Installazione</title>
  16. </head>
  17. <body>
  18. <center><h1>Installazione</h1></center>
  19. <table>
  20. <tr><td>
  21. <form action="?send=1" method="post">
  22. </td></tr>
  23. <tr><td><b>Dati per la connessione al MySQL</b></td></tr>
  24. <tr><td>Hostname:</td><td><input type="text" name="host" value="localhost"/></td></tr>
  25. <tr><td>Username:</td><td><input type="text" name="user" /></td></tr>
  26. <tr><td>Password:</td><td><input type="password" name="pass" /></td></tr>
  27. <tr><td>DB Name:</td><td><input type="text" name="dbname"/></td></tr><br />
  28. <input type="submit" value="Installa!" name="send" />
  29. </form>
  30. </table>
  31.  
  32. <?php
  33.  
  34. if(@$_GET['send'] == 1) {
  35.  
  36.     if (isset($_POST['host'])
  37.     && isset($_POST['user'])
  38.     && isset($_POST['pass'])    
  39.     && isset($_POST['dbname'])) {
  40.    
  41. //Dati Connessione MySQL
  42. $host = $_POST['host'];
  43. $user = $_POST['user'];
  44. $passwd = $_POST['pass'];
  45. $dbname = $_POST['dbname'];
  46.  
  47. $conn = mysql_connect ($host , $user ,$passwd) or die(mysql_error());
  48.         mysql_select_db ($dbname,$conn) or die(mysql_error());
  49.    
  50. //creo la prima SQL da eseguire
  51. $sql = "CREATE TABLE project (
  52.    `id` int(11) NOT NULL auto_increment,
  53.    `titolo` TEXT NOT NULL,
  54.    `username` TEXT NOT NULL,
  55.    `commento` TEXT NOT NULL,
  56.    `data` TEXT NOT NULL,
  57.    `ip` TEXT NOT NULL,
  58.    
  59.    PRIMARY KEY ( id )
  60. );";
  61.  
  62. mysql_query($sql) or die ("SQL Error:".mysql_error());//eseguo la prima SQL, se da errori li stampo
  63.     echo "<font color=\"green\">Table 'project' creata</font><br />\n";
  64.  
  65.        
  66. // creazione contenuto file config.php
  67. $config='<?php
  68.  
  69. $host = "'.$host.'";
  70. $user = "'.$user.'";
  71. $passwd = "'.$passwd.'";
  72. $dbname = "'.$dbname.'";
  73.  
  74.  
  75. $conn = mysql_connect($host, $user, $passwd) or die(mysql_error()); //connetto al DB
  76.           mysql_select_db($dbname, $conn) or die(mysql_error()); //Seleziono il DB
  77. ?>';
  78.    
  79.         // Scriviamo sul config.php i dati che ci occorrono
  80.     if(!($open = fopen( "config.php", "w" )))
  81.         die("Errore durante l'apertura sul file config.php");
  82.  
  83.     fwrite ($open, $config);//Scrivo sul file config.php
  84.    
  85.     fclose ($open); // chiudo il file
  86.  
  87.     echo "<font color=\"green\">File 'config.php' creato con successo</font><br />\n";
  88.             echo "<font color=green>Installazione avvenuta con successo!</font>"; //stampo l'avvenuto successo di installazione
  89.             } else {
  90.             print "<script>alert('riempire tutti i campi');</script>";
  91.                                }
  92. }      
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement