Jump to content

login script


etsted

Recommended Posts

every time i log in i get a good message displaying, you have been logged in, but then when i try to click on another link it automatically loges me out why?
<?php
session_start();
?>
<html>
<head>
<link href='style/style.css' rel='stylesheet' type="text/css" />
<title>Login</title>
<meta name='login' content='login to itsnature' />
<meta name='keywords' content='login' />
</head>
<body>
<h1>Login</h1>
<?php
require_once "connect.php";
// sets a navigator
if(isset($username))
{
include "navigator/navigator_login.php";
}
else
{
include "navigator/navigator.php";
}
// login form
$login = "<form action='login.php' method='POST' name='login1' class='forgotpass'>
<input type='text' name='username' placeholder='Username' /> <br />
<input type='password' name='password' placeholder='Password' />
<input type='submit' name='submit' value='Login' /> |
<a href='register.php'>Register</a>
</form>";
// includes a navigator
if(isset($username))
{
echo "<p>Welcome $username.</p> <br />";
}
else
{
if(isset($_POST['username']) && isset($_POST['password']))
{
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
}
if(isset($username) && isset($password))
{
$password = md5($password);
$query = mysqli_query($con ,"SELECT * FROM users WHERE username='$username' && password='$password'");
$numrows = mysqli_num_rows($query);
if($numrows != 0)
{
$_SESSION['username'] = $username;
echo "<p>You have been logged in.</p> <br />";
}
else
{
echo "<p>Wrong password or username.</p>$login";
}
}
else
{
echo "<p>You must register an account in order to login.</p>$login";
}
}
mysqli_close($con);
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...