Jump to content

Member only page


bravo14

Recommended Posts

Hi guys

 

I am trying to create a member only section of a site and display the user name at the top next to the Welcome note.  The page is displaying correctly except for the user name

 

<?
session_start(); 
if (!isset($_SESSION['logname']))
{
header ("Location: login.php");
}
else
{
echo'<html>';
echo'<head>';
echo'<title>• Yardley Hockey Club • Admin • Control Panel •</title>';
echo'<link href="../style/2008.css" rel="stylesheet" type="text/css" />';
echo'</head>';
echo'<body>';
echo'<div id="maintext">';
include_once('includes/connector.php');
$logname=$_SESSION['logname'];
$sql = "SELECT * FROM `tbl_admin_users` where username ='$logname'";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result));
echo('Welcome ' .$row[username].'.');
include_once('includes/9.php');

}
?>
</div>
</body>
</html>

 

I know that someone out there can help

Link to comment
Share on other sites

You really should save the user name in a session, otherwise you will rack up tons of queries on your db

 

 

Exactly, don't use a query in your username everytime the page loads are you crazy!! =)

 

Use the session instead.

 

$_SESSION['username'];

 

Also, if the user is an administrative user, you should save that in a session too.

 

All of these sessions should be created during login.

 

I personally like to create a session that is set to TRUE if the user is logged in, then I can do this:

 

session_start();
if(!$_SESSION['logged']){
   // user is not logged in redirect back home
   header("Location: /");
   exit;
}
// this is a logged in user do what ever else you want below...

Link to comment
Share on other sites

I'm with these guys. Store the user in the session when you run the log in script. Then there is only one query and it is always available in $_SESSION for other pages. I usually store other info in the session as well like the unique key of the user and whatever other details you may need to identify him in queries down the road.

 

 

Like The Little Guy said, if he is an admin, throw that in, too.

 

$_SESSION['USER']['is_admin'] = true

$_SESSION['USER']['user_id'] = '1234'

$_SESSION['USER']['user_first'] = 'John'

$_SESSION['USER']['user_nick'] = 'John123'

 

That kind of stuff is always useful. You may want to break it up like I did with all your USER info in one container and so on... If it is just a simple thing that only deals with users, you don't have to.

Link to comment
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.