Answers for "login system php"

PHP
6

php console log

// Assuming you are wishing to log to the JS Console...

<?php
	function consoleLog($msg) {
		echo '<script type="text/javascript">' .
          'console.log(' . $msg . ');</script>';
	}

	consoleLog('Hello, console!');
?>
Posted by: Guest on March-07-2020
3

login PHP

<?php
session_start();// come sempre prima cosa, aprire la sessione 
include("db_con.php"); // Include il file di connessione al database
$_SESSION["username"]=$_POST["username"]; // con questo associo il parametro username che mi è stato passato dal form alla variabile SESSION username
$_SESSION["password"]=$_POST["password"]; // con questo associo il parametro username che mi è stato passato dal form alla variabile SESSION password
$query = mysql_query("SELECT * FROM users WHERE username='".$_POST["username"]."' AND password ='".$_POST["password"]."'")  //per selezionare nel db l'utente e pw che abbiamo appena scritto nel log
or DIE('query non riuscita'.mysql_error());
// Con il SELECT qua sopra selezione dalla tabella users l utente registrato (se lo è) con i parametri che mi ha passato il form di login, quindi
// Quelli dentro la variabile POST. username e password.
if(mysql_num_rows($query)>0){        //se c'è una persona con quel nome nel db allora loggati
$row = mysql_fetch_assoc($query); // metto i risultati dentro una variabile di nome $row
$_SESSION["logged"] =true;  // Nella variabile SESSION associo TRUE al valore logge
header("location:prova.php"); // e mando per esempio ad una pagina esempio.php// in questo caso rimanderò ad una pagina prova.php
}else{
echo "non ti sei registrato con successo"; // altrimenti esce scritta a video questa stringa di errore
}
?>
Posted by: Guest on May-28-2021
3

how to make a working login system using code

<!DOCTYPE html>
<html>
<head>
	<title>Login</title>
	<script>
  firebase.initializeApp(firebaseConfig);
  const auth = firebase.auth();
  function signUp(){
    var email = document.getElementById("email");
    var password = document.getElementById("password");
    const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
    promise.catch(e => alert(e.message));
    alert("Signed Up");
  }
  function signIn(){
    var email = document.getElementById("email");
    var password = document.getElementById("password");
    const promise = auth.signInWithEmailAndPassword(email.value, password.value);
    promise.catch(e => alert(e.message));
  }
  function signOut(){
    auth.signOut();
    alert("Signed Out");
  }

auth.onAuthStateChanged(function(user){
    if(user){
      var email = user.email;
      alert("Signed in as " + email);
      //Take user to a different or home page

      //is signed in
    }else{
      alert("No Active User");
      //no user is signed in
    }
  });g
	</script>
<style type="text/css">
	body{
	background-color: #55d6aa;
}
h1{
	background-color: #ff4d4d;
	margin: 10px auto;
	text-align: center;
	color: white;
}
#formContainer{
	background-color: white;
	box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);

	width: 25%;
	height: 45;
	margin: 10px auto;
}
#header{
	width: 100%;
	height: 10px;
	background: black;
}
#email{
	width: 70%;
	height: 40px;
	display:block;
	margin: 25px auto;
	border: none;
	outline: none;
	border-bottom: 2px solid black;
}
#password{
	width: 70%;
	height: 40px;
	display: block;
	margin: 10px auto;
	border: none;
	outline: none;
	border-bottom: 2px solid black;
}
#signUp{
	background-color: #ff4d4d;
	color: white;
	border: none;
	font-weight: bold;
	padding: 15px 32px;
	border-radius: 10px;
	text-align: center;
	text-decoration: none;
	display: inline-block;
	font-size: 13px;
	margin-top: 20px;
	margin-left: 50px;
}
#signIn{
	background-color: #32ff7e;
	color: white;
	font-weight: bold;
	border: none;
	padding: 15px 35px;
	border-radius: 10px;
	text-align: center;
	text-decoration: none;
	font-size: 13px
}
#signOut{
	background-color: #FFA500;
	color: white;
	border: none;
	padding: 12px 32px;
	border-radius: 10px;
	text-align: center;
	text-decoration: none;
	display: inline-block;
	font-size: 13px;
	margin-top: 9px;
	margin-left: 74px;
	font-weight: bold;
}
button: hover{
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 7px 50px 0 rgba(0,0,0,0,.19);
}
</style>
</head>
<body>
	<h1>Login Here</h1>
	<div id="formContainer">
		<div id="header"> </div>
  <input type="email" placeholder="Email" id="email">
  <input type="password" placeholder="Password" id="password">

 <button onclick="signUp()" id="signUp"> Sign Up </button>
  <button onclick="signIn()" id="signIn"> Sign In </button>
  <button onclick="signOut()" id="signOut"> Sign Out </button>
Continue</a>
</body>
</html>
Posted by: Guest on November-30-2020
-1

login php

<?php 
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
</head>
<body>
    <form action="" method="POST">
        <input type="password" name="password">
        <button type="submit" name="submit">Login</button>
    </form>
    <?php 
    if(isset($_POST['submit'])){
        if(password_verify($_POST['password'], '$2y$10$sejeRNYZGaoPh1EwfcuO1.hxl/uepQOh9SITWWgeej86vnMt26KIa')){
                        $_SESSION['login'] = true;
          header("Location: http://localhost");
        }
    }
?>
</body>
</html>
Posted by: Guest on December-17-2020

Browse Popular Code Answers by Language