el problema es que despues de logearme no me redirige a la pagina de perfil
[PHP]
/*INDEX.PHP*/
<!DOCTYPE html>
<html>
<head>
<title>index.php</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.14.1/math.min.js"></script>
<link href="config.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="form-riconoscimento">
<h4>modulo di riconoscimento</h4>
<button onclick="generateUsername()">genera username</button>
<table>
<form method="post" action="server.php">
<tr>
<td><input type="text" name="username" id="username" required></td>
</tr>
<tr>
<td><input type="password" name="password" placeholder="password"></td>
</tr>
<tr>
<td><input type="radio" name="opzioneUtente" value="registerUser">registrasi</td></tr>
<tr>
<td><input type="radio" name="opzioneUtente" value="logUser" checked>accedere</td>
</tr>
<tr>
<td><input type="submit" value="invio"></td></tr>
</form>
</table>
</div>
<script type="text/javascript">
function generateUsername(){
codeAlfa = "HAvc13nmsdw";
codealfa = codeAlfa.split(""); //return array
codefinal = [];
for(i=0; i<=codealfa.length; i++){
codefinal.push(codealfa[math.randomInt(codealfa.length)]) ;
}
code = codefinal.join(""); //return string
document.getElementById("username").value=code;
}
username = document.getElementById("username");
if(navigator.userAgent == "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
{username.setAttribute("value", "crom");
}
else if(navigator.userAgent == "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0")
{username.setAttribute("value", "firefox"); }
</script>
</body>
</html>
[/PHP]
[PHP]
<?php
/*SERVER.PHP*/
session_start();
$conex = mysql_connect('localhost', 'root');
mysql_select_db("my_laboraccio", $conex);
/*variabili di index.php*/
$uname = $_POST['username'];
$pw = $_POST['password'];
$opzioneUtente = $_POST['opzioneUtente'];
/*variabili di profilo.php */
echo $_GET['sms'];
if($_POST['sessione'] == "logout") {
session_unset();
session_destroy();
header("Refresh:10; url=http://www.laboraccio.altervista.org/");
echo "session expired";
}
function registerUser(){
global $uname;
echo $uname;
global $pw;
$sql = "SELECT * FROM utenti WHERE username='$uname'";
$resource = mysql_query($sql) or die (mysql_error());
$result = mysql_num_rows($resource);
echo $result;
if($result == 0) {
$sql = "INSERT INTO utenti (id, username, password) VALUES (NULL, '$uname', '$pw')";
mysql_query($sql);
header("Refresh:10; url=http://www.laboraccio.altervista.org/");
echo "new user created";
echo "register succesful";
}
elseif($result == 1){
echo "username already in use, try again with another one";
header("Refresh:10; url=http://www.laboraccio.altervista.org/");
}
}
function logUser(){
global $uname;
global $pw;
$sql = "SELECT * FROM utenti WHERE username='$uname' AND password='$pw'";
$resource = mysql_query($sql) or die (mysql_error());
$result = mysql_num_rows($resource);
if($result == 1) {
$_SESSION['username'] = $uname;
$_SESSION['password'] = $pw;
echo "welcome to the personal area".$uname;
header("location:http://www.laboraccio.altervista.org/profilo.php");
}
elseif($result == 0) {print "username wrong";
header("Refresh:10; url=http://www.laboraccio.altervista.org/");
}
}
if($opzioneUtente == 'registerUser'){
registerUser();
}
elseif($opzioneUtente == "logUser") {
logUser();
}
?>
[/PHP]
[PHP]
<?php
/*PROFILO.PHP*/
session_start();
if(!isset($_SESSION['username'])) {
header("location: http://laboraccio.altervista.org/");
}
if(isset($_SESSION['username'])){
echo $_SESSION['username'];
}
?>
[/PHP]