Jump to content

Session login system does not work...


t.bo

Recommended Posts

Hi all...

I just tried my first code using sessions but there is something wrong. I always get "Your login is wrong" while I enter the correct username and pw. The username is correctly inputted though...

Here is the code Login.htm:
[code]<form action="login.php" method="post">
<b>Username</b>:<input type="text" name="username" size="20"><br>
<b>Password</b>:<input type="password" name="pw" size="20"><br>
<input type="submit" value="Login"></form>[/code]

Login.php:
[code]<?php
session_start();
include('dbconnect.php');
$username = $_GET[username];
$pw = $_GET[pw];
$q="SELECT * FROM `login` WHERE ((username='$username') AND (pw='$pw'))";
$result= mysql_query($q) or die ("Could not execute query : $q." . mysql_error());

if (mysql_num_rows($result) == 0)
{
echo "<div align=center><b>Your login is wrong. Please click back and try again.</b></div>";
}
else
{
$r=mysql_fetch_array($result);
$login_username=$r["username"];
session_register("login_username");
Header("Location: protected.php");
}
?>[/code]

and finally protected.php
[code]<?php
session_start();
if ($_SESSION["login_username"]=="") {
Header("Location: login.htm");
} else {

echo "U r logged in...";
}

?>[/code]

Hope someone can help me out...
Grtz and thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.