Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.