• Home
  • Forum
  • Fare Web
  • PHP

UserPie, sicuro e "a passo coi tempi"?

  • Creatore Discussione Creatore Discussione Marco Bonanno
  • Data di inizio Data di inizio 27 Mar 2015
Prec.
  • 1
  • 2
Primo Prec. 2 di 2
M

Marco Bonanno

Utente Attivo
3 Lug 2012
32
0
6
  • 5 Apr 2015
  • #21
Grazie mille ancora una volta, ricordo di aver visto già questa funziona in uno script, perfetto.
Mentre ci sono, ho aggiornato un po il codice riguardo l'update dei dati del profilo (Una volta riuscito con questo poi cercherò di fare lo stesso con la password, che sicuramente non cambierà molto.).

Ho fatto cosi:

Codice:
//submit
if(isset($_POST['submit'])) {

	$email = $_POST['email'];
	$gender = $_POST['gender'];
    $location = $_POST['location'];
	
    if($user->update($email,$gender,$location)) {
        redirect('account.php');
    }
}

e sempre nella pagina account.php

Codice:
<form action="" method="POST">
<table width="500" border="1" cellpadding="5">
<tbody>
<tr>
<th scope="row" width="154">Email</th>
<td width="314"><input type="text" name="email" size="30" value="<?php echo $_SESSION['email']; ?>" /></td>
</tr>
<tr>
<th scope="row">Gender</th>
<td><input type="text" name="gender" size="30" value="<?php echo $_SESSION['gender']; ?>" /></td>
</tr>
<tr>
<th scope="row">Location</th>
<td><textarea cols="20" name="location" rows="5"><?php echo $_SESSION['location']; ?></textarea></td>
</tr>
<tr>
<th scope="row"></th>
<td>
<input type="hidden" name="id" value="<?php echo $_SESSION['memberID']; ?>" />
<input type="submit" name="submit" value="Save" /></td>
</tr>
</tbody>
</table>
</form>

Invece, nella classe user ho inserito questo:

Codice:
// Update profile
    public function update($email,$gender,$location) {
        try {
        $stmt = $this->_db->prepare('UPDATE members SET email = ?, gender = ?, location = ? WHERE memberID = ? ');
        $stmt->execute(array($email,$gender,$location));
        return $stmt->fetch();
        } catch(PDOException $e) {
            echo '<p class="bg-danger">'.$e->getMessage().'</p>';
        }
    }

Sicuramente avrò sbagliato la parte finale, per quanto riguarda i "?" credo di aver seguito correttamente il tuo consiglio di sopra, penso.
 

flameseeker

Utente Attivo
27 Nov 2013
699
0
0
  • 5 Apr 2015
  • #22
Per capire se c'è qualcosa che non va con la questione dei placeholders nelle query, ti basta contare il numero di punti di domanda che hai inserito..
Codice:
email = ?
gender = ? 
location = ? 
memberID = ?
..e paragonarli ai dati che stai effettivamente inviando:
PHP:
$stmt->execute(array($email,$gender,$location));

Direi che ti manca il memberID


Altra cosa che noto è che il form che hai scritto ha il parametro action vuoto:
HTML:
<form action="" method="POST">

Dovrebbe contenere il nome della pagina che contiene il tuo codice di submit.
 
M

Marco Bonanno

Utente Attivo
3 Lug 2012
32
0
6
  • 5 Apr 2015
  • #23
Ho appena provato, inserendo le variabili dell'ID utente dove di dovuto, almeno spero, ma uguale rilascia il seguente errore quando provo ad inviare i nuovi dati:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
 

flameseeker

Utente Attivo
27 Nov 2013
699
0
0
  • 5 Apr 2015
  • #24
Posta nuovamente il tuo metodo di update, così vediamo come hai modificato
 
M

Marco Bonanno

Utente Attivo
3 Lug 2012
32
0
6
  • 5 Apr 2015
  • #25
Ho eliminato per il momento il campo gender per semplicità, quindi la classe user ho fatto cosi:

Codice:
    // Update profile
    public function update($id,$email,$location) {
        try {
        $stmt = $this->_db->prepare('UPDATE members SET memberID = ?, email = ?, location = ? WHERE memberID = ? ');
        $stmt->execute(array($id,$email,$location));
        return $stmt->fetch();
        } catch(PDOException $e) {
            echo '<p class="bg-danger">'.$e->getMessage().'</p>';
        }
    }

Poi, nel file account.php

Codice:
//submit
if(isset($_POST['submit'])) {

	$email = $_POST['email'];
    $location = $_POST['location'];
	
    if($user->update($email,$location)) {
        redirect('changepw.php');
    }
}

Ho provato sia cosi che inserendo anche la variabile $id con POST id

ed il form:

Codice:
<form action="changepw.php" method="POST">
<table width="500" border="1" cellpadding="5">
<tbody>
<tr>
<th scope="row" width="154">Email</th>
<td width="314"><input type="text" name="email" size="30" value="<?php echo $_SESSION['email']; ?>" /></td>
</tr>
<tr>
<th scope="row">Location</th>
<td><textarea cols="20" name="location" rows="5"><?php echo $_SESSION['location']; ?></textarea></td>
</tr>
<tr>
<th scope="row"></th>
<td>
<input type="hidden" name="memberID" value="<?php echo $_SESSION['memberID']; ?>" />
<input type="submit" name="submit" value="Save" /></td>
</tr>
</tbody>
</table>
</form>

L'errore che mi restituisce è questo:

[05-Apr-2015 20:03:34 Europe/London] PHP Warning: Missing argument 3 for User::update(), called in /home/marcobon/public_html/last/account.php on line 15 and defined in /home/marcobon/public_html/last/classes/user.php on line 59

Quindi a quanto pare è il richiamo della funzione update che non è corretto.
 

flameseeker

Utente Attivo
27 Nov 2013
699
0
0
  • 5 Apr 2015
  • #26
Perdonami, sono stato poco chiaro: quando intendevo che ti manca il memberID intendevo che nell'execute non passavi il riferimento di sessione che identifica il tuo utente.

Riporta il codice a com'era prima e modifica l'execute della query in questo modo:
PHP:
$stmt->execute(array($email,$gender,$location,$_SESSION['member_id']));

(assumendo che il valore di sessione member_id è presente da quando ti ho scritto questa replica)
 
M

Marco Bonanno

Utente Attivo
3 Lug 2012
32
0
6
  • 11 Apr 2015
  • #27
Ciao, ritorno su questa discussione per lo stesso problema che ancora non sono riuscito a risolvere.
Ho provato in tanti modi in questi giorni, è quello che sto per incollare è l'ultimo che ho preso da esempio da un altro script.

*** Preciso che per il motivo appena detto, i nomi assegnati alle variabili indicano altro, ad esempio su $lastname io ho impostato sotto la location, fa confusione lo so.

Nella classe user:

Codice:
    // update user
    public function update_user($firstname, $lastname, $gender, $user_id){
        
        $this->username = $firstname;
        $this->location  = $lastname;
        $this->gender     = $gender;
        $this->memberID     = $user_id;
        
        $query = $this->_db->prepare("UPDATE `members` SET
        
        `username`	   = ?,
        `location`	   = ?,
        `gender`          = ?
        WHERE `memberID` 	   = ?");
        
        $query->bindValue(1, $this->username, PDO::PARAM_STR);
        $query->bindValue(2, $this->location, PDO::PARAM_STR);
        $query->bindValue(3, $this->gender, PDO::PARAM_STR);
        $query->bindValue(4, $this->memberID, PDO::PARAM_INT);
        
        try{
            $query->execute();
        }catch(PDOException $e){
            die($e->getMessage());
        }
    }

Mentre nell'ipotetica pagina account.php

Codice:
if(isset($_POST['update-submit'])){		
    require 'classes/Validation.php';
    $val = new Validation();
    $val->addSource($_POST);
    $rules_array = array(
        'first-name'=>array('type'=>'string',  'required'=>true, 'min'=>0, 'max'=>32, 'trim'=>true),
        'last-name'=>array('type'=>'string',  'required'=>true, 'min'=>0, 'max'=>32, 'trim'=>true),
		'gender'=>array('type'=>'string',  'required'=>true, 'min'=>0, 'max'=>1, 'trim'=>true));
   $val->addRules($rules_array);
   $val->run();
   $san[] = $val->sanitized;
   if(sizeof($val->errors) > 0){
      $val_errors[] = $val->errors;
   }else{
   try{  
      $firstname = $san[0]['first-name'];
	  $lastname = $san[0]['last-name'];
	  $gender = $san[0]['gender'];
       $user_id = $_SESSION['memberID'];
    
	   $user->update_user($firstname, $lastname, $gender, $user_id);
       $_SESSION['message'] = "Your profile has been updated!";
       header("Location: account.php");
       exit();   
    }catch(PDOException $e){
        $errors[] = $e->getMessage();
    }
   }
 }

Ed relativo form:

Codice:
<form action="" method="post" id="settings-form" enctype="multipart/form-data">
<div class="personal-info">
<h3>Change Profile Information</h3>

<?php if(!empty($errors)){
     echo '<p class="error">' . implode('</p><p>', $errors) . '</p>';
 } if(!empty($val_errors)){ 
     echo '<p class="error">' . implode('</p><p>', $val_errors[0]) . '</p>';
 }
    ?>
        
    <label for="first-name">Username:</label><br />
    <input type="text" name="first-name" id="first-name" value="<?php if(isset($_POST['first-name'])){
        echo htmlspecialchars($_POST['first-name'], ENT_QUOTES); } 
else { echo htmlspecialchars($_SESSION['username'], ENT_QUOTES); 
     }?>">
    
    <br />
	<label for="last-name" >Location:</label><br />
	<input type="text" name="last-name" id="last-name" value="<?php if(isset($_POST['last-name'])){
	                                                                   echo htmlspecialchars($_POST['last-name'], ENT_QUOTES);
	                                                                }else{
																	   echo htmlspecialchars($_SESSION['location'], ENT_QUOTES);
																	}?>">
    <br />
	<label for="gender">Gender:</label><br />
    <?php
       $gender 	= $_SESSION['gender'];
       $options 	= array("","M", "F");
       echo '<select name="gender" id="gender">';
       foreach($options as $option){
          if($gender == $option){
              $sel = 'selected="selected"';
          }else{
              $sel='';
          }
       echo '<option '. $sel .'>' . $option . '</option>';
        }
    ?>
       </select>
	    
  </div>
  <div class="clear"></div>
  <hr />
  <span>Update Changes:</span>
  <input type="submit" name="update-submit" value="Update">  
  </form>


Non genera nessun errore al file error_log, ma non va ugualmente :/
 
Prec.
  • 1
  • 2
Primo Prec. 2 di 2
Devi accedere o registrarti per poter rispondere.

Discussioni simili

Z
Upload protetto e sicuro
  • z.cristiano
  • 6 Set 2021
  • PHP
Risposte
1
Visite
737
PHP 6 Set 2021
linoma
L
Simple cross-site requests ovvero processare richieste in modo sicuro
  • MarcoGrazia
  • 10 Apr 2019
  • Snippet PHP
Risposte
5
Visite
2K
Snippet PHP 24 Ott 2019
marino51
W
[PHP] Login sicuro al web Service SOAP
  • w_t
  • 11 Mag 2018
  • PHP
  • 2
Risposte
20
Visite
6K
PHP 14 Mag 2018
w_t
W
Sono y sicuro sanno!
  • lucofol
  • 1 Lug 2017
  • Webdesign e Grafica
Risposte
1
Visite
2K
Webdesign e Grafica 2 Lug 2017
leonardogreco3
Come si fa a controllare se un sito è sicuro?
  • max_400
  • 17 Nov 2016
  • Sicurezza e Virus
Risposte
2
Visite
4K
Sicurezza e Virus 2 Dic 2016
MarcoGrazia
A
Come mettere al sicuro un Cloud Server?
  • andreto
  • 17 Feb 2016
  • Cloud Computing e Cloud Server
Risposte
1
Visite
2K
Cloud Computing e Cloud Server 9 Lug 2018
IKOULA CLOUD
A
problema form login sicuro
  • Andreotti99
  • 5 Feb 2015
  • PHP
Risposte
0
Visite
2K
PHP 5 Feb 2015
Andreotti99
A
Come ncludere file in modo sicuro per prevenire attacchi
  • xone
  • 4 Apr 2014
  • PHP
Risposte
0
Visite
1K
PHP 4 Apr 2014
xone
G
Io ho trovato il metodo per guadagnare onesto e sicuro.entrate.
  • gaetano
  • 28 Dic 2011
  • Guadagnare col Sito
Risposte
2
Visite
3K
Guadagnare col Sito 2 Gen 2012
Angix
V
Login sicuro al 100%, Come?
  • Vicar
  • 5 Ott 2011
  • PHP
Risposte
6
Visite
3K
PHP 7 Ott 2011
Vicar
V
A
guadagno sicuro
  • adrianono
  • 8 Set 2011
  • Guadagnare col Sito
Risposte
0
Visite
2K
Guadagnare col Sito 8 Set 2011
adrianono
A
Inviare Foto nello spazio web in modo sicuro
  • max_400
  • 19 Lug 2011
  • PHP
Risposte
3
Visite
3K
PHP 19 Lug 2011
max_400
GuadagnaSicuro - il mio forum pagante
  • tonylson
  • 28 Gen 2011
  • Presenta il tuo Sito
Risposte
0
Visite
1K
Presenta il tuo Sito 28 Gen 2011
tonylson
W
Streaming video Sicuro !!!
  • w_t
  • 16 Set 2010
  • Ajax
Risposte
4
Visite
2K
Ajax 28 Nov 2010
imtiaz8181
I
il login in php è sicuro?
  • max_400
  • 13 Set 2010
  • PHP
Risposte
14
Visite
7K
PHP 15 Set 2010
max_400
P
info su sistema di pagamento sicuro in Joomla
  • peppejam
  • 12 Mag 2010
  • Joomla
Risposte
0
Visite
2K
Joomla 12 Mag 2010
peppejam
P
P
Pagamento sicuro Online PHP
  • phpista
  • 4 Mag 2010
  • PHP
Risposte
3
Visite
2K
PHP 4 Mag 2010
MarcoGrazia
I
login sicuro
  • iacoposk8
  • 7 Lug 2009
  • PHP
Risposte
4
Visite
3K
PHP 4 Apr 2010
grossini
G
D
guadagnare mentre si e' collegati....e' possibile e anche sicuro!!!!!!!!!!!
  • denver
  • 7 Ago 2006
  • Altri Annunci
Risposte
1
Visite
1K
Altri Annunci 7 Ago 2006
dead
D
S
Aiuto Web Service Sicuro
  • superciccio14
  • 9 Mar 2006
  • Programmazione
Risposte
0
Visite
2K
Programmazione 9 Mar 2006
superciccio14
S
Condividi:
Facebook X (Twitter) LinkedIn WhatsApp e-mail Condividi Link
  • Home
  • Forum
  • Fare Web
  • PHP
  • Italiano
  • Termini e condizioni d'uso del sito
  • Policy Privacy
  • Aiuto
  • Home
Community platform by XenForo® © 2010-2024 XenForo Ltd. | Traduzione a cura di XenForo Italia
Menu
Accedi

Registrati

  • Home
  • Forum
    • Nuovi Messaggi
    • Cerca...
  • Novità
    • Featured content
    • Nuovi Messaggi
    • Ultime Attività
X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?

X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?