Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 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.                     //controllo inserimento campi
  36.     if(empty($_POST['host']) || empty($_POST['user']) || empty($_POST['pass']) || empty($_POST['dbname']))
  37.         die("<script>alert('Inserisci tutti i dati'); window.loading=\"index.php\";</script>");
  38. }
  39.     if (isset($_POST['host'])
  40.     && isset($_POST['user'])
  41.     && isset($_POST['pass'])    
  42.     && isset($_POST['dbname'])) {
  43.    
  44. //Dati Connessione MySQL
  45. $host = $_POST['host'];
  46. $user = $_POST['user'];
  47. $passwd = $_POST['pass'];
  48. $dbname = $_POST['dbname'];
  49.  
  50. $conn = mysql_connect ($host , $user ,$passwd) or die(mysql_error());
  51.         mysql_select_db ($dbname,$conn) or die(mysql_error());
  52.    
  53. //creo la prima SQL da eseguire
  54. $sql = "CREATE TABLE project (
  55.    `id` int(11) NOT NULL auto_increment,
  56.    `titolo` TEXT NOT NULL,
  57.    `username` TEXT NOT NULL,
  58.    `commento` TEXT NOT NULL,
  59.    `data` TEXT NOT NULL,
  60.    `ip` TEXT NOT NULL,
  61.    
  62.    PRIMARY KEY ( id )
  63. );";
  64.  
  65. mysql_query($sql) or die ("SQL Error:".mysql_error());//eseguo la prima SQL, se da errori li stampo
  66.     echo "<font color=\"green\">Table 'project' creata</font><br />\n";
  67.  
  68.        
  69. // creazione contenuto file config.php
  70. $config='<?php
  71.  
  72. $host = "'.$host.'";
  73. $user = "'.$user.'";
  74. $passwd = "'.$passwd.'";
  75. $dbname = "'.$dbname.'";
  76.  
  77.  
  78. $conn = mysql_connect($host, $user, $passwd) or die(mysql_error()); //connetto al DB
  79.           mysql_select_db($dbname, $conn) or die(mysql_error()); //Seleziono il DB
  80. ?>';
  81.    
  82.         // Scriviamo sul config.php i dati che ci occorrono
  83.     if(!($open = fopen( "config.php", "w" )))
  84.         die("Errore durante l'apertura sul file config.php");
  85.  
  86.     fwrite ($open, $config);//Scrivo sul file config.php
  87.    
  88.     fclose ($open); // chiudo il file
  89.  
  90.     echo "<font color=\"green\">File 'config.php' creato con successo</font><br />\n";
  91.             echo "<font color=green>Installazione avvenuta con successo!</font>"; //stampo l'avvenuto successo di installazione
  92.             }
  93.            
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement