- Home
- Categorie
- Coding e Sistemistica
- Coding
- Problemi con login
-
Problemi con login
Girovagando su internet ho trovato una chat semplice semplice in PHP con database.
<?php include 'config2.php' ?> </head> <body> <script>apertura_pagina();</script> <br><br><br><br> <table border=0 align=center id="tabella" height=200px width=500px> <tr> <td style="font-size:13px" valign=top> <div style="overflow: auto;width: 100%; height: 175px"> <?php $query = mysql_query("SELECT * FROM `_chat` ORDER BY `TIME` ASC"); while($result = mysql_fetch_array($query)) { print "<b>".$result['UTENTE']." : </b> ".$result['POST']." <br>" ; } ?> </div> </td> </tr> <tr> <td height=25px style="border-color:grey;"> <form action="" method="POST" style="margin:0px;padding=0px;"> <input type="text" name="testo" style="width: 430px; border-style:solid; background-color:grey;" /> <input type="hidden" name="utente" value="<?php print htmlspecialchars(@$_COOKIE['nome_utente']); ?>" /> <input type="submit" name="submit" value="INVIA" style="border-style:solid; border-color:black;background-color:grey;" /> </form> </td> </tr> </table> <?php if(!empty($_POST['testo']) && !empty($_POST['utente'])) { $text = mysql_real_escape_string( htmlentities( stripslashes( $_POST['testo'] ))); $utente = mysql_real_escape_string( htmlentities( stripslashes( $_POST['utente'] ))); mysql_query("INSERT INTO `chat` (`TIME` ,`UTENTE` ,`POST` )VALUES ( NOW( ), '{$utente}', '{$text}');"); print " <script language='JavaScript'>aggiorna()</script> "; } ?>
Tabella DB
CREATE TABLE `chat` ( `TIME` TEXT NOT NULL , `UTENTE` TEXT NOT NULL , `POST` TEXT NOT NULL );
Funziona bene. Per il nick c' è un funzione in javascript che a me non piace. Vorrei creare un login con inserimento nick, senza cookies, ecc,,, (senza reg) e che poi quel nick inserito deve uscire come autore quando scrivo messaggi in chat. Non riesco uff...Mi aiutate??
-
Vedi se funziona così
Sicuramente ci sarà da modificare e adattare qualcosina.[PHP]<?php
session_start();
include 'config2.php';
?>
</head>
<body>
<br><br><br><br>
<table border=0 align=center id="tabella" height=200px width=500px>
<tr>
<td style="font-size:13px" valign=top>
<div style="overflow: auto;width: 100%; height: 175px">
<?phpif(isset($_POST['nick']) && !empty($_POST['nick']) ){
$_SESSION['nick'] = htmlentities(addslashes($_POST['nick']));
}if(isset($_SESSION['nick'])){
$query = mysql_query("SELECT * FROM
_chat
ORDER BYTIME
ASC");while($result = mysql_fetch_array($query)) {
print "<b>".$result['UTENTE']." : </b> ".$result['POST']." <br>" ;
}
} else {
echo '<form method="post" action="?set=nick">
Inserisci il tuo nickname per la chat: <input type="text" name="nick" value="">
<input type="submit" value=" accedi alla chat ">';
}
?>
</div>
</td>
</tr>
<tr>
<td height=25px style="border-color:grey;">
<form action="" method="POST" style="margin:0px;padding=0px;">
<input type="text" name="testo" style="width: 430px; border-style:solid; background-color:grey;" />
<input type="hidden" name="utente" value="<?php print htmlspecialchars($_SESSION['nick']); ?>" />
<input type="submit" name="submit" value="INVIA" style="border-style:solid; border-color:black;background-color:grey;" />
</form>
</td>
</tr>
</table>
<?php
if(!empty($_POST['testo']) && !empty($_POST['utente'])) {$text = mysql_real_escape_string( htmlentities( stripslashes( $_POST['testo'] )));
$utente = mysql_real_escape_string( htmlentities( stripslashes( $_POST['utente'] )));mysql_query("INSERT INTO
chat
(TIME
,UTENTE
,POST
)VALUES (
NOW( ), '{$utente}', '{$text}');");print " <script language='JavaScript'>aggiorna()</script> ";
}
?>[/PHP]
-
Grazie Mille! Saresti gentile da farmi il login a parte??