Forum Moderators: coopster
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?
<?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";
}
?>