<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[classe php]]></title><description><![CDATA[<p dir="auto">salve a tutti, ho provato a creare una classe che abbia i metodi necessari a ricevere i dati da un form e salvarli in un file, dopo aver verificato l' input dell' utente e di avere i permessi sui file.<br />
ecco cosa mi è uscito</p>
<pre><code class="language-php">&lt;?php
 class Scrivifile {
  public $file="iscritti.txt";
  public $nome;
  public $cognome;
  public $mail;
                       
public function __construct() {   
                                                                                                      
 $this-&gt;nome=$_POST['nome'];
 $this-&gt;cognome=$_POST['cognome'];
 $this-&gt;mail=$_POST['mail'];
}

public function Controllodati ($nome,$cognome,$mail) {
 if(!isset($this-&gt;nome) ||!$this-&gt;nome || !isset($this-&gt;cognome) || !$this-&gt;cognome )
 return FALSE;
 else return TRUE;
 }
public function Controllomail($mail) {
 trim($this-&gt;mail);
  
    if(!$email)    
        return FALSE;   
       
    $num_at = count(explode( '@', $this-&gt;mail )) - 1;   
    if($num_at != 1)    
        return FAlSE;   
       
  
    if(strpos($this-&gt;mail,';') || strpos($this-&gt;mail,',') || strpos($this-&gt;mail,' '))    
        return FALSE;   
       
    if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $this-&gt;mail))   
        return FALSE;  
        
return TRUE;
 
}
public function Controllofile ($file) {
if (is_writable($this-&gt;file) &amp;&amp; feof($this-&gt;file))
       return TRUE;
       else return FALSE;
}
public function Scrittura ($file) {
if($this-&gt;Controllodati($nome,$cognome,$mail) &amp;&amp; $this-&gt;Controllomail($mail) &amp;&amp; Controllofile($file)) {
 if(fopen($this-&gt;file,a)) {
 $dascrivere="$this-&gt;nome | $this-&gt;cognome |  $this-&gt;mail/r/n";
 fwrite($this-&gt;file,$dascrivere);
 fclose($this-&gt;file);
 }
    else echo "errore nell' apertura del file, ci scusiamo per l' inconveniente";
}
else if(!$this-Controllodati($nome, $cognome, $mail) || !$this-&gt;Controllomail($mail))
echo "I dati da te immessi sono errati, la preghiamo di ricontrollarli" ;
}
}
?&gt;
</code></pre>
<p dir="auto">facendo il debug non è sorto nessun errore, ma ho molte perplessità sul codice.<br />
E' concettualmente giusto come sono strutturate le funzioni?<br />
Come potrei indentare e rendere più efficente e funzionale questa stessa classe' Cosa è consigliabile che modifichi?<br />
Insomma, secondo voi è scritta bene o si poteva scrivere notevolmente meglio?<br />
Grazie delle risposte , ciao a tutti</p>
]]></description><link>https://dev.connect.gt/topic/75654/classe-php</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 01:24:36 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/75654.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Jun 2008 18:05:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to classe php on Sat, 28 Jun 2008 10:38:56 GMT]]></title><description><![CDATA[<p dir="auto">grazie della risposta,il tuo script non restituisce errori ma il metodo Scrittura() non scrive nulla...<br />
Avevo cambiato gli script in questo modo che mi sembrava giusto, ma non vanno ugualmente... qual'è l' errore in questi? grazie mille delle risposte<br />
classe1.inc</p>
<pre><code class="language-php">&lt;?php
 class Scrivifile {
 public $file="iscritti.txt";
 public $nome;
 public $cognome;
 public $mail;
                       
public function __construct($in_nome, $in_cognome, $in_mail, $in_file) {   
                                                                                                      
 $this-&gt;nome= $in_nome;
 $this-&gt;cognome=$in_cognome;
 $this-&gt;mail=$in_mail;
 $this-&gt;file=$in_file;
}

protected function Controllodati () {
 $in_nome = $this-&gt;nome;
 $in_cognome = $this-&gt;cognome;
 if(!$in_nome || !$in_cognome )
 return FALSE;
 else return TRUE;
 }
protected function Controllomail() {
 $in_mail = $this-&gt;mail;
 trim($in_mail);
  $num_at = count(explode( '@', $in_mail )) - 1;
    if(!$in_mail)    
        return FALSE;   
       
    else if($num_at != 1)    
        return FAlSE;   
       
    else if(strpos($in_mail,';') || strpos($in_mail,',') || strpos($in_mail,' '))    
        return FALSE;   
       
   else  if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $in_mail))   
        return FALSE;  
        
        else return TRUE;
       
        
 
}
protected function Controllofile () {
$in_file = $this-&gt;file;
if (is_writable($in_file) &amp;&amp; feof($in_file))
       return TRUE;
       else return FALSE;
}
public function Scrittura () {
$in_file = $this-&gt;file;
if($this-&gt;Controllodati() &amp;&amp; $this-&gt;Controllomail() &amp;&amp; $this-&gt;Controllofile()) {
 if($fp=fopen($in_file,"a")) {
 $dascrivere="$this-&gt;nome | $this-&gt;cognome |  $this-&gt;mail/r/n";
 fwrite($fp,$dascrivere);
 fclose($fp);
 }
    else echo "errore nell' apertura del file'";
}
else if (!$this-&gt;Controllodati() || !$this-&gt;Controllomail())
echo "I dati da te immessi sono errati, la preghiamo di ricontrollarli" ;
}
?&gt;
</code></pre>
<p dir="auto">script1.php</p>
<pre><code class="language-php">&lt;?php
include ("classe1.inc");
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
$mail=$_POST['mail'];
$scrivifile = new Scrivifile($nome,$cognome,$mail,$file);
$scrivifile-&gt;Scrittura();
?&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/730335</link><guid isPermaLink="true">https://dev.connect.gt/post/730335</guid><dc:creator><![CDATA[jappoz]]></dc:creator><pubDate>Sat, 28 Jun 2008 10:38:56 GMT</pubDate></item><item><title><![CDATA[Reply to classe php on Sat, 28 Jun 2008 09:08:32 GMT]]></title><description><![CDATA[<p dir="auto">è molto logico che ti dia errore <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61b.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--stuck_out_tongue" style="height:1.4em;width:auto;vertical-align:middle" title=":P" alt="😛" /></p>
<pre><code class="language-php">&lt;?php
 class Scrivifile {
  private $file="iscritti.txt";
  private $nome;
  private $cognome;
  private $mail;
                       
public function __construct($nome,$cognome,$mail) {   
                                                                                                      
 $this-&gt;nome=$nome;
 $this-&gt;cognome=$cognome;
 $this-&gt;mail=$mail;
}

public function Controllodati () {
 if(!isset($this-&gt;nome) ||!$this-&gt;nome || !isset($this-&gt;cognome) || !$this-&gt;cognome )
 return FALSE;
 else return TRUE;
 }
public function Controllomail() {
 trim($this-&gt;mail);
  
    if(!$this-&gt;mail)    
        return FALSE;   
       
    $num_at = count(explode( '@', $this-&gt;mail )) - 1;   
    if($num_at != 1)    
        return FAlSE;   
       
  
    if(strpos($this-&gt;mail,';') || strpos($this-&gt;mail,',') || strpos($this-&gt;mail,' '))    
        return FALSE;   
       
    if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $this-&gt;mail))   
        return FALSE;  
        
return TRUE;
 
}
public function Controllofile () {
if (is_writable($this-&gt;file) &amp;&amp; feof($this-&gt;file))
       return TRUE;
       else return FALSE;
}
public function Scrittura () {
if($this-&gt;Controllodati($nome,$cognome,$mail) &amp;&amp; $this-&gt;Controllomail($mail) &amp;&amp; Controllofile($file)) {
 if(fopen($this-&gt;file,a)) {
 $dascrivere="$this-&gt;nome | $this-&gt;cognome |  $this-&gt;mail/r/n";
 fwrite($this-&gt;file,$dascrivere);
 fclose($this-&gt;file);
 }
    else echo "errore nell' apertura del file, ci scusiamo per l' inconveniente";
}
else if(!$this-Controllodati($nome, $cognome, $mail) || !$this-&gt;Controllomail($mail))
echo "I dati da te immessi sono errati, la preghiamo di ricontrollarli" ;
}
}
?&gt;
</code></pre>
<p dir="auto">quindi:</p>
<pre><code class="language-php">&lt;?php
include ("classe1.inc");
$scrivifile = new Scrivifile($_POST[nome],$_POST[cognome],$_POST[mail]);
$scrivifile-&gt;Controllodati();
$scrivifile-&gt;Controllomail();
$scrivifile-&gt;Controllofile();
$scrivifile-&gt;Scrittura();
?&gt;
</code></pre>
<p dir="auto">prova</p>
]]></description><link>https://dev.connect.gt/post/730325</link><guid isPermaLink="true">https://dev.connect.gt/post/730325</guid><dc:creator><![CDATA[massimux]]></dc:creator><pubDate>Sat, 28 Jun 2008 09:08:32 GMT</pubDate></item><item><title><![CDATA[Reply to classe php on Wed, 25 Jun 2008 21:44:40 GMT]]></title><description><![CDATA[<p dir="auto">se tutti, ho un problema proprio con questa classe<br />
facendo partire questa mini applicazione formata da<br />
un form html (pagina1.htm)</p>
<pre><code class="language-html">&lt;form action="script1.php" method="POST"&gt;
&lt;input type="text" name="nome" /&gt; Immetti il nome &lt;br&gt;
&lt;input type="text" name="cognome" /&gt; Immetti il cognome &lt;br&gt;
&lt;input type="text" name="mail" /&gt; Metti qui la tua mail &lt;br&gt;
&lt;input type="submit" value="invia" /&gt;
&lt;/form&gt;
</code></pre>
<p dir="auto">una classe .inc (vedere quella postata sopra)<br />
uno script php linkato al method del form (script1.php)</p>
<pre><code class="language-php">&lt;?php
include ("classe1.inc");
$scrivifile = new Scrivifile;
$scrivifile-&gt;Controllodati($nome,$cognome,$mail);
$scrivifile-&gt;Controllomail($mail);
$scrivifile-&gt;Controllofile($file);
$scrivifile-&gt;Scrittura($file);
?&gt;
</code></pre>
<p dir="auto">Quando faccio una prova, immettendo dati sbagliati mi da il messaggio di errore, ma anche mettendo quelli giusti<br />
Mi sto scervellando da ore e ho capito che c'è qualcosa che non va nella classe, ma non so cosa! Ho provato di tutto, potete aiutarmi perfavore?</p>
]]></description><link>https://dev.connect.gt/post/730334</link><guid isPermaLink="true">https://dev.connect.gt/post/730334</guid><dc:creator><![CDATA[jappoz]]></dc:creator><pubDate>Wed, 25 Jun 2008 21:44:40 GMT</pubDate></item></channel></rss>