Forum Moderators: coopster

Message Too Old, No Replies

Login issue

         

dave1236

9:12 pm on Sep 2, 2006 (gmt 0)

10+ Year Member



All:

I am trying to set my pages up so that you can navigate from page to page without logging in. Currently, I have it set up so that if a user does not login, they are directed to a login page. Here is some code I use...

<?php
session_start();
if (@$_SESSION['auth']!= "yes")
{
echo "you are not logged in";
}
include("connect.inc");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");
$sql = "SELECT firstName,lastName FROM Registered
WHERE loginName='{$_SESSION['logname']}'";
$result = mysql_query($sql)
or die("Couldn't execute query 1.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
extract($row);
echo "<html>

<body>

You are logged in as $firstName $lastName";
?>

When this script runs, if they do not login, they get the notation "You are not logged in" but "You are logged in as..." also prints.

Basically, what I want to accomplish is is if they have NOT logged in, they are reminded they aren't - in short, like how many sites (Yahoo for example) present content to you regardless of login status. When you do login, then it switches to tell you that you are logged in.

Suggestions?

smatts9

12:43 am on Sep 3, 2006 (gmt 0)

10+ Year Member



Well you have it so if they are not logged in the it will tell you that they are because you did not include an else part to your script so it only does the top part try this:


<?php
session_start();
if (@$_SESSION['auth']!= "yes")
{
echo "you are not logged in";
} else {
include("connect.inc");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");
$sql = "SELECT firstName,lastName FROM Registered
WHERE loginName='{$_SESSION['logname']}'";
$result = mysql_query($sql)
or die("Couldn't execute query 1.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
extract($row);
echo "<html>

<body>

You are logged in as $firstName $lastName";
}
?>

dave1236

4:22 am on Sep 3, 2006 (gmt 0)

10+ Year Member



Thanks!

That worked perfectly!

Appreciate the advice!