Jump to content

Member only page


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


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



I know that someone out there can help

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




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:


   // user is not logged in redirect back home
   header("Location: /");
// this is a logged in user do what ever else you want below...

Link to post
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 post
Share on other sites


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.