Комментарии:
The user's input is not sanitized and it is used in session variable...
But after all, it's a good start
Hey, for the index.php altough im setting the html exactly as you, i just keep getting a blank page, any ideas?
Ответитьthank you so much
ОтветитьI have just come back to this and everything bar 1 thing works. If I put the url in for the login.php page I can access it. I shouldn't be able to acess it unless I have logged in, how can I ensure this is the case?
ОтветитьHey, man!
Thanks for this work.
I'm from brazil, and this tutorial helped me a lot to make a job for university.
Thanks one more time!
i tried adding the php code to my website, but when i enter values in the form and click on login, the page where the session is started doesn't show, the login page stays the same
ОтветитьIf you go directly to the login page, what happens ? Does this not make the login thing completely useless ?
Ответитьhooi!
ik krijg deze foutmelding wat moet ik doen?
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FORM gebruikers WHERE Gebruikersnaam = kevin AND Wachtwoord = 123' at line 1' in C:..\wwwroot\inc\inloggen.php:26 Stack trace: #0 C:..\wwwroot\inc\inloggen.php(26): PDOStatement->execute() #1 C:..\wwwroot\inloggen.php(57): include('C:\\domains\\vane...') #2 {main} thrown in C:..\wwwroot\inc\inloggen.php on line 26
code:
<?php
session_start();
$servername = "localhost";
$username = "...";
$password = "...";
try {
$conn = new PDO("mysql:host=$servername;dbname=...", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "ERROR: " . $e->getMessage();
echo "<br>";
echo "Geen goede database connectie. Herlaad deze pagina.";
}
if (isset($_POST['inloggen'])) {
$gebruikersnaam = $_POST['gnaam'];
$wachtwoord = $_POST['wwoord'];
$query = $conn->prepare("SELECT COUNT ID FORM ... WHERE Gebruikersnaam = $gebruikersnaam AND Wachtwoord = $wachtwoord");
$query->execute();
$count = $query->fetchColumn();
if ($count == "1"){
$_SESSION['gebruikersnaam'] = $gebruikersnaam;
header ('location: ingelogd/index.php');
}
}
?>
Thank you :)
ОтветитьFatal error: Call to undefined method PDO::execute() in C:\xamp\htdocs\Webphp\index.php on line 12
Ответить<?php
session_start();
$conn = new PDO('mysql:host=localhost;dbname=logintutorial', 'root', '');
if(isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$query = $conn->prepare("SELECT COUNT('id') FROM 'users' WHERE 'username' = '$username' AND 'password' = '$password'");
$query = $conn->execute();
$count = $query->fetchColumn();
if($count == "1"){
$_SESSION['username'] = $username;
header('location: login.php');
}
}
?>
Hi there, I tried making the same thing without a password, but it won't log in, even though I have edited the code so that it would work (or at least I think so)
Here's the code, can you tell me if I did something wrong here, and if so, how I can fix it?
<?php
session_start();
$conn = new PDO('mysql:host=localhost;dbname=t3inf', 'root', '');
if(isset($_Post['login'])){
$username = $_post['username'];
$query = $conn->prepare("SELECT COUNT('id') FROM 'users' WHERE 'username' = '$username'");
$query->execute();
//Kind regards.
I have got this to work but what i want to do is have two diffrent login scanerios depending on who logs in i was trying to do this with the if count = 1 load a certain page else if count = 2 load a diffrent page is thsi possible thanks
ОтветитьNice tutorial, I have been looking for this for a while. Thanks
ОтветитьError -->Try : $query = $conn->prepare("SELECT COUNT(id) FROM users WHERE username = '$username' AND password = '$password'");
Ответитьhi, i swear I'm doing this right but my login page keeps coming up blank, i don't think the index page is connecting properly to the login page, if you could help me out would really appreciate it
ОтветитьI'm doing the same thing than you and it doesn't works
ОтветитьNothing happens when i try to login. The textbox just get empty when i submit :( please help
ОтветитьThanks for uploading this, do you also know how to hash the passwords so, you can't see them in the database?
ОтветитьMy favorite videos are the ones that have sound.
ОтветитьMichiko;
Your session is not started.
put an isset around it,
if (isset($_SESSION['username']{
echo "Welkom" . $_SESSION['username'];
}
this will prevent showing errors.
Also check your login script to make sure the username session is set.
$_SESSION['username] = true must be set.
You can check by using the var_dump function like
Var_dump($_SESSION['username']);
<?php
session_start();
echo "Welcome" . $_SESSION['username'];
if(isset($_POST['logout'])){
session_start();
session_destroy();
header('location: index.php');
}
?>
<html>
<head>
<title>Logged in</title>
</head>
<body>
<form method = "post" name = "logout">
<input type = "submit" name="logout" value="log me out">
</form>
</body>
</html>
Notice: Undefined index: username in C:\wamp\www\Work_it\login.php on line 4
i followed your tutorial but after I ran the program it gave an error T__T help please :D Thank you so much
thanks...
ОтветитьHow would you make this a registration form?
Ответитьsecurity ... security ...
Ответитьthanks!!! best regards from chile :)
Ответитьcan you please send me the program used by email :
[email protected]
i'll be very greatful
good video this is what i needed for a project because i did follow a tutorial where he makes a login system for a cms but that thing didn't work so this will work
btw hoi land genoot