Jump to content

user logon session failing


ntroycondo

Recommended Posts

My logon script is redirecting to the correct page without error but that page doesn't show the user logged on and echos "You Must be Logged In". Any thing look out of place?

 

 

 

Redirected page:

<?php

session_start();

 

if ($_SESSION['username'])

echo "Welcome, ".$_SESSION['username']."!";

else

die("You must be logged in!");

 

?>

 

 

 

Logon.php script:

 

<?php

session_start();

$username = $_POST['user_name'];

$password = $_POST['password'];

$password = md5($password);

 

if ($username&&$password)

{

$connect = mysql_connect("host", "root", "password") or die("Couldn't connect");

mysql_select_db("myDB") or die("Couldn't find DB");

 

$query = mysql_query("SELECT * FROMmyDB_users WHERE user_name='$username'");

 

$numrows = mysql_num_rows($query);

 

if ($numrows!=0)

{

 

while ($row = mysql_fetch_assoc($query))

{

$dbusername = $row['user_name'];

$dbpassword = $row['password'];

}

 

if ($username==$dbusername&&$password==$dbpassword)

{

header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/"."member.php");

mysql_free_result ($result); // Free up the resources.

###exit();

### echo "Welcome! <a href='member.php'>Click</a> here.";

###$_SESSION['username']=$username;

}

else

echo "Incorrect password!";

}

else

die("User does not exist");

 

 

}

else

die("Please enter user name and password.");

 

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/205621-user-logon-session-failing/
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.