Jump to content

Login Help


carleihar

Recommended Posts

 

login.php:

<?php
session_start();

//Login form (login.php)

include "../includes/db_connect.inc.php";
if(!$_POST['submit'])
{
?>
<html>
<b><Login</b>
<form method="post" action="user_home.php">
Username<input type="text" name="username" maxlength="16">
Password<input type="password" name="password" maxlength="16">
<input type="submit" name="submit" value="Login">
</form>
<a href="register.php">Register Here</a>
</html>

<?php
}
else
{
  $user = mysql_real_escape_string($_POST['username']);
  $pass = mysql_real_escape_string($_POST['password']);

if($user && $pass)
{
$pass = md5($pass); //compare the encrypted password
$sql="SELECT user_id,username FROM `users` WHERE `username`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($query) == 1)
    {
      $row = mysql_fetch_assoc($query); // mysql_fetch_assoc gets the value for each field in the row
      $_SESSION['user_id'] = $row['user_id']; //creates the first session var
      $_SESSION['username'] = $row['username']; // second session var
	  header ('Location: http://liveequian.com/htdocs/pages/user_home.php');

    }
    else
   {
    echo "Username is incorrect.";
    }	
}
else
{			
    echo "Please enter your username and password.";
}
}
?>

 

 

user_home.php:

<?php 
session_start();
//home.php
if($_SESSION['user_id'])
{
echo "Welcome ",$_SESSION['username'] ;
echo '<a href="logout.php">Logout</a>' ;
}
else
{
echo "You don't belong here!";
}
?>

 

 

I'm getting to user_home.php, but it's reporting "You don't belong here!" Help?

 

The columns in my SQL database are user_id, username, password.

Link to comment
https://forums.phpfreaks.com/topic/181435-login-help/
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.