@giulio-marchesi ha detto in texarea quando si invia il testo emette un suono:
<script> function f(){ const suono = new Audio("nomefile.mp3"); suono.play(); } </script>
buongiorno e grazie per la risposta meglio javascript
@giulio-marchesi ha detto in texarea quando si invia il testo emette un suono:
<script> function f(){ const suono = new Audio("nomefile.mp3"); suono.play(); } </script>
buongiorno e grazie per la risposta meglio javascript
@merlinox ciao ho usato chatGPT e mi ha generato funziona alla grande! l'ho inserito nel file dove salva i messaggi sul daatabase
<?php
$myAudioFile = "suoni/whisper.wav";
echo '<audio autoplay="true" style="display:none;">
<source src="'.$myAudioFile.'" type="audio/wav">
</audio>';
?>
ciao a tutti come posso fare in modo che quando un utente scrive nella texarea al clik emette un suono?
Buongiorno sono riuscito a risolvere certo non è un gran che ma va bene e funziona posto il codice
<?php
session_start();
include('../db.conn.php');
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = $conn->prepare("SELECT * FROM users WHERE username=:username");
$query->bindParam("username", $username, PDO::PARAM_STR);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
if (!$result) {
$em = "Il nome utente non risulta registrato!";
header("Location: ../../index.php?error=$em");
} else {
if (password_verify($password, $result['password'])) {
$_SESSION['user_id'] = $result['user_id'];
$_SESSION['username'] = $result['username'];
$_SESSION['name'] = $result['name'];
header("Location: ../../home.php");
echo '<p class="success">Accesso eseguito con successo!</p>';
} else {
$em = "Nome utente o password errata!";
header("Location: ../../index.php?error=$em");
}
}
}
?>
salve non riesco a capire perchè se un utente non registrato prova a effettuare l'accesso da pagina bianca come posso risolvere? chiedo aiuto posto i codici
<form method="post"
action="app/http/auth.php">
<div class="d-flex
justify-content-center
align-items-center
flex-column">
<h3 class="display-4 fs-1
text-center">
</h3>
</div>
<?php if (isset($_GET['error'])) { ?>
<div class="alert alert-warning" role="alert">
<?php echo htmlspecialchars($_GET['error']);?>
</div>
<?php } ?>
<?php if (isset($_GET['success'])) { ?>
<div class="alert alert-success" role="alert">
<?php echo htmlspecialchars($_GET['success']);?>
</div>
<?php } ?>
<div class="mb-3">
<label class="form-label">
Nome utente</label>
<input type="text"
class="form-login"
name="username">
</div>
<div class="mb-3">
<label class="form-label">
Password</label>
<input type="password"
class="form-login"
name="password">
</div>
<button type="submit"
class="btn btn-outline-secondary">
Accedi</button>
<a class="btn btn-outline-secondary" href="signup.php" role="button">Registrati</a>
<hr>
<br>
<a class="btn btn-outline-secondary" href="recupero.php" role="button">Password dimenticata?</a>
</form>
----------------------------------------------
<?php
session_start();
# check if username & password submitted
if(isset($_POST['username']) &&
isset($_POST['password'])){
# database connection file
include '../db.conn.php';
# get data from POST request and store them in var
$password = $_POST['password'];
$username = $_POST['username'];
$data = "username=".$username;
#simple form Validation
if(empty($username)){
# error message
$em = "inserisci il nome utente";
# redirect to 'index.php' and passing error message
header("Location: ../../index.php?error=$em&$data");
}else if(empty($password)){
# error message
$em = "inserisci la password";
# redirect to 'index.php' and passing error message
header("Location: ../../index.php?error=$em&$data");
}else {
$sql = "SELECT * FROM
users WHERE username=?";
$stmt = $conn->prepare($sql);
$stmt->execute([$username]);
# if the username is exist
if($stmt->rowCount() === 1){
# fetching user data
$user = $stmt->fetch();
# if both username's are strictly equal
if ($user['username'] === $username) {
# verifying the encrypted password
if (password_verify($password, $user['password'])) {
# successfully logged in
# creating the SESSION
$_SESSION['username'] = $user['username'];
$_SESSION['name'] = $user['name'];
$_SESSION['user_id'] = $user['user_id'];
# redirect to 'home.php'
header("Location: ../../home.php");
}else {
# error message
$em = "Nome utente o password errati";
# redirect to 'index.php' and passing error message
header("Location: ../../index.php?error=$em&$data");
}
}else {
# error message
$em = "Nome utente o password errati";
# redirect to 'index.php' and passing error message
header("Location: ../../index.php?error=$em&$data");
}
}
}
}else {
header("Location: ../../index.php");
exit;
}
@oceweb ciao e buona domenica sono riuscito a eliminare la chat ora sia l'utente A e B possono eliminare la chat ma la conversazione la può eliminare solo chi invia o chi riceve non riesco a capire cosa manca posto i codici ```
<?php
function getConversation($user_id, $conn){
/**
Getting all the conversations
for current (logged in) user
**/
$sql = "SELECT * FROM conversations
WHERE user_1=? OR user_2=?
ORDER BY conversation_id DESC";
$stmt = $conn->prepare($sql);
$stmt->execute([$user_id, $user_id]);
if($stmt->rowCount() > 0){
$conversations = $stmt->fetchAll();
/**
creating empty array to
store the user conversation
**/
$user_data = [];
# looping through the conversations
foreach($conversations as $conversation){
# if conversations user_1 row equal to user_id
if ($conversation['user_1'] == $user_id) {
$sql2 = "SELECT *
FROM users WHERE user_id=?";
$stmt2 = $conn->prepare($sql2);
$stmt2->execute([$conversation['user_2']]);
}else {
$sql2 = "SELECT *
FROM users WHERE user_id=?";
$stmt2 = $conn->prepare($sql2);
$stmt2->execute([$conversation['user_1']]);
}
$allConversations = $stmt2->fetchAll();
# pushing the data into the array
array_push($user_data, $allConversations[0]);
}
return $user_data;
}else {
$conversations = [];
return $conversations;
}
}
---------------------------
<ul id="chatList"
class="list-group mvh-50 overflow-auto">
<?php if (!empty($conversations)) { ?>
<?php
foreach ($conversations as $conversation){ ?>
<li class="list-group-item">
<a href="chat.php?user=<?=$conversation['username']?>"
class="d-flex
justify-content-between
align-items-center p-2">
<div class="d-flex
align-items-center">
<img src="uploads/<?=$conversation['p_p']?>"
class="w-10 rounded-circle">
<h3 class="fs-xs m-2">
<?=$conversation['name']?><br>
<small>
<?php
echo lastChat($_SESSION['user_id'], $conversation['user_id'], $conn);
?>
</small>
</h3>
</div>
<?php if (last_seen($conversation['last_seen']) == "Active") { ?>
<div title="online">
<div class="online"></div>
</div>
<?php } ?>
</a>
<a href="deleteconv.php?user_2=<?=$conversation['user_id']?>" class="btn btn-danger"><i class="fa fa-trash-o"></i> Elimina messaggi</a>
</li>
@overclokk si concordo in effetti come ho già scritto la chat l'ho scaricata su YouTube fino al 2005 programmavo il mirc con il vincula lo usavo per proteggere le ex chat msn sinceramente era più facile scrivere il codice
@oceweb ciao e buongiorno non capisco perchè le conversazioni che sono nella home.php riesco a eliminarla solo con: user_1 oppure user_2 ma se provo a inserire conversation_id non funziona posto il codice dove stampa a video le conversazioni
function getConversation($user_id, $conn){
/**
Getting all the conversations
for current (logged in) user
**/
$sql = "SELECT * FROM conversations
WHERE user_1=? OR user_2=?
ORDER BY conversation_id DESC";
$stmt = $conn->prepare($sql);
$stmt->execute([$user_id, $user_id]);
if($stmt->rowCount() > 0){
$conversations = $stmt->fetchAll();
/**
creating empty array to
store the user conversation
**/
$user_data = [];
# looping through the conversations
foreach($conversations as $conversation){
# if conversations user_1 row equal to user_id
if ($conversation['user_1'] == $user_id) {
$sql2 = "SELECT *
FROM users WHERE user_id=?";
$stmt2 = $conn->prepare($sql2);
$stmt2->execute([$conversation['user_2']]);
}else {
$sql2 = "SELECT *
FROM users WHERE user_id=?";
$stmt2 = $conn->prepare($sql2);
$stmt2->execute([$conversation['user_1']]);
}
$allConversations = $stmt2->fetchAll();
# pushing the data into the array
array_push($user_data, $allConversations[0]);
}
return $user_data;
}else {
$conversations = [];
return $conversations;
}
}
@oceweb ariciao ho fatto come mi hai detto e funziona! grazie x l'aiuto
@oceweb ciao sinceramente non ho provato come mi hai detto ti mostro il codice dove preleva i messaggi sia inviati e ricevuti e li mostra nel file chat.php
<?php
function getChats($id_1, $id_2, $conn){
$sql = "SELECT * FROM chats
WHERE (from_id=? AND to_id=?)
OR (to_id=? AND from_id=?)
ORDER BY chat_id ASC";
$stmt = $conn->prepare($sql);
$stmt->execute([$id_1, $id_2, $id_1, $id_2]);
if ($stmt->rowCount() > 0) {
$chats = $stmt->fetchAll();
return $chats;
}else {
$chats = [];
return $chats;
}
}
?>
@oceweb ciao questa è la struttura delle tabelle sia conversazione e chat
-- Struttura della tabella `chats`
--
CREATE TABLE `chats` (
`chat_id` int(11) NOT NULL,
`from_id` int(11) NOT NULL,
`to_id` int(11) NOT NULL,
`message` text NOT NULL,
`opened` tinyint(1) NOT NULL DEFAULT 0,
`create_datetime` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- --------------------------------------------------------
--
-- Struttura della tabella `conversations`
--
CREATE TABLE `conversations` (
`conversation_id` int(11) NOT NULL,
`user_1` int(11) NOT NULL,
`user_2` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
@overclokk ciao no non ho risolto riesco a eliminare chi invia ma no chi riceve ho riprovato ma elimina chi riceve ma no chi invia come posso fare per eliminare sia chi riceve e chi invia? ho scaricato la chat messaggio privato su YouTube in effetti in fase di registrazione non controlla se la mail è esistente il sito l'ho caricato sul mio dominio fcfclean.it/sito utente Francesco pass albachiara/12 è una pass di test sono riuscito anche a resettare la pass dimenticata non sono un programmatore ma autodidatta il sito è x l'amministratore di condominio dove i condomini si registrano e possono scaricare i doc inviati da l'amministratore e cambiare la foto profilo ho fatto anche la parte admin devo dire che non credo che il sito sia sicuro sto cercando un programmatore logico pagando x sistemare ciò
salve sto tentando di eliminare una chat la sessione è username ma non ci riesco dove sbaglio?
<a href="delchat.php<?=$chat['message']?><?=$chat['to_id']?>" class="btn btn-danger"><i class="fa fa-trash-o"></i> Delete</a>
file delchat.php
<?php
include 'app/db.conn.php';
$get_id = $_GET['to_id'];
$conn->query("delete from chats where to_id = '$get_id'");
header('location:home.php');
?>
buongiorno sto tentando di eliminare due tabelle ho provato cosi ma non va :
CREATE TABLE `chats` (
`chat_id` int(11) NOT NULL,
`from_id` int(11) NOT NULL,
`to_id` int(11) NOT NULL,
`message` text NOT NULL,
`opened` tinyint(1) NOT NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `conversations`
--
CREATE TABLE `conversations` (
`conversation_id` int(11) NOT NULL,
`user_1` int(11) NOT NULL,
`user_2` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-----------------------------------------------------------
<?php
session_start();
# check if the user is logged in
if(isset($_POST['del'])){
# database connection file
include 'app/db.conn.php';
# get the logged in user's username from SESSION
$user_id = $_SESSION['user_id'];
$chat_id = $_POST['chat_id'];
$conversation_id = $_POST['conversation_id'];
$sql = "DELETE chats,conversations
FROM chat_id AS chats
LEFT JOIN conversation_id AS conversations ON chat_id.from_id = conversation_id.conversation_id
WHERE chat_id.from_id = 2;'");
$stmt= $conn->prepare($sql);
$stmt->execute([$chat_id, $conversation_id]);
header("Location: home.php");
exit;
}
?>
<form action="delchat.php" method="post" enctype="multipart/form-data">
<input type="hidden" value="<?=$user['username']?>">
<input type="submit" name="del" value="Elimina chat">
</form>
salve sto tentando di eliminare due record sul database ma non riesco a farlo funzionare sicuramente sbaglierò qualcosa
<ul id="chatList"
class="list-group mvh-50 overflow-auto">
<?php if (!empty($conversations)) { ?>
<?php
foreach ($conversations as $conversation){ ?>
<li class="list-group-item">
<p>Elimina chat</p>
<form action="delchat.php" method="post" enctype="multipart/form-data">
<input name="chat_id"/>
<input type="hidden" value="<?= $_SESSION['name'] ?>">
<input type="submit" name="del" value="Elimina chat">
</form>
<a href="chat.php?user=<?=$conversation['username']?>"
class="d-flex
justify-content-between
align-items-center p-2">
<div class="d-flex
align-items-center">
<img src="uploads/<?=$conversation['p_p']?>"
class="w-10 rounded-circle">
<h3 class="fs-xs m-2">
<?=$conversation['username']?><br>
<?=$conversation['name']?><br>
<small>
<?php
echo lastChat($_SESSION['user_id'], $conversation['user_id'], $conn);
?>
</small>
------------------------------------------
file delchat.php
<?php
include('app/db.conn.php');
if (isset($_POST['del'])){
$chat_id=$_POST['chat_id'];
mysqli_query($conn,"delete from `chats` where chat_id='$chat_id'");
mysqli_query($conn,"delete from `conversations` where conversation_id='$conversation_id'");
header("Location: home.php");
}
?>
ciao e buongiorno non riesco a capire perchè mi da errore su session start e header qualcuno può aiutarmi? Grazie
<?php
session_start(); //errore
header('Content-type: text/html; charset=ISO-8859-1'); //errore
function captcha() {
$numb1 = rand(1, 9);
$numb2 = rand(1, 9);
$sommanumeri = $numb1 + $numb2;
$moltipnumeri = $numb1 * $numb2;
$operazioni = array(
1 => $sommanumeri,
2 => $moltipnumeri
);
$rand = rand(1, 2);
$_SESSION['antispam'] = $operazioni[$rand];
$str1 = $numb2;
$str2 = $numb1;
$rand_strings = array_rand(array_flip(array($str1, $str2)), 1);
if ($rand == 1) {
return $str1 . ' + ' . $str2;
} else {
return $str1 . ' x ' . $str2;
}
}
$risultato = NULL;
$errore_captcha = NULL;
if (isset($_POST['submit'])) {
$mittente = (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) ? stripslashes(trim($_POST['mittente'])) : trim($_POST['mittente']);
switch ($_POST['reparto']) {
case 'generico':
$email_destinatario = '[email protected]';
break;
case 'amministrazione':
$email_destinatario = '[email protected]';
break;
case 'privato':
$email_destinatario = '[email protected]';
break;
}
if ( !preg_match('/^[.a-zA-Z0-9\-\'\s]{1,40}$/', $mittente) || !preg_match('/^[.a-z0-9_-]+@[.a-z0-9_-]+\.[a-z]{2,4}$/', $_POST['email_mittente']) || !preg_match('/^[0-9]{6,10}$/', $_POST['telefono']) || empty($_POST['messaggio']) ) {
$risultato = '<div id="error" style="color: #FF0000;"><span class="testonorm">Riempire tutti i campi in maniera corretta!</span></div>';
}
else {
if ($_POST['spamcode'] != @$_SESSION['antispam']) {
$errore_captcha = '<div id="error" style="color:;"><span class="testonorm">Risposta antispam errata!</span></div>';
}
else {
$messaggio = (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) ? stripslashes(strip_tags($_POST['messaggio'])) : strip_tags($_POST['messaggio']);
$phpversion = (!@phpversion()) ? "N/A" : phpversion();
$header = "From: " . $mittente . " <" . $_POST['email_mittente'] . ">\n";
$header.= "Reply-To: " . $_POST['email_mittente'] . "\n";
$header.= "Return-Path: " . $_POST['email_mittente'] . "\n";
$header.= "X-Mailer: PHP " . $phpversion . "\n";
$header.= "MIME-Version: 1.0\n";
$header.= "Content-type: text/plain; charset=ISO-8859-1\n";
$header.= "Content-Transfer-encoding: 7bit\n";
if (@mail($email_destinatario, "Mail inviata da fcfclean.it", "\nDa: " . $mittente . " (" . $_POST['email_mittente'] . " - IP: " . $_SERVER['REMOTE_ADDR'] . ")\n\nTelefono: " . $_POST['telefono'] . "\n\nTesto messaggio: \n$messaggio", $header)) {
$risultato = '<div id="success" style="color #3A14FB;"><span class="testonorm"><strong>Email inviata, risponderemo il prima possibile Grazie.</strong></span></div>';
header('refresh: 4; url=' . $_SERVER['PHP_SELF']);
}
else {
$risultato = '<div id="error" style="color: #3C6;"><span class="testonorm">Si è verificato un errore: riprova più tardi</span></div>';
header('refresh: 4; url=' . $_SERVER['PHP_SELF']);
}
}
}
}
?>