Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2005, 08:25 PM
Authorized User
 
Join Date: Nov 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hide div unless user logged in

Hi, I'm really rather new to php so I thought I'd dive in at the deep end...
I have a message board system which displays the message with any comment that have been posted on the message shown below it, with the form to post a new message below that.
I'm using a dreamweaver function to log the user in and I want to hide the form to post new messages unless the user is logged in.
I'm really not sure how to do this and I really don't want to resort to having a seperate page for the form and restricting all access to it if at all possible.

If anyone can help please do, and if you need any of my code (not that I have written any to try and do this yet) feel free to ask for it.

Cheers all..
 
Old January 20th, 2005, 10:31 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Depending on your method of keeping track of logged in users, try something like:

Code:
<?php
if(isset($_SESSION['logged_in'])) {
?>
FORM CODE HERE
<?php } ?>
hth,

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old January 21st, 2005, 02:43 AM
Authorized User
 
Join Date: Nov 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks for the reply...

Like I said I'm using Dreamweaver for the log in script, mainly because I'm not competant enough with PHP to write my own as of yet.
That script seems to be setting the session variables

Code:
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;
    session_register("MM_Username");
    session_register("MM_UserGroup");
I have tried your suggestion of

Code:
<?php if (isset($_SESSION['MM_Username'])) { ?>
form code here
<?php } ?>
And it does a wonderful job of hiding it, yet it does not seem to be working even when I am logged in.

I tried to simply echo the session variable MM_Username but it won't even do that, so I'm assuming there is something wrong with my variable declaration or the actual registering of the variable.
 
Old January 21st, 2005, 06:43 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try switching around the lines you posted to make it like this:

session_register("MM_Username");
session_register("MM_UserGroup");
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

Or better yet, leave out the session_register lines altogether. session_register is a depreciated function and uneeded:
http://www.php.net/session-register

Good luck,

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old January 21st, 2005, 08:21 PM
Authorized User
 
Join Date: Nov 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou very much for the help... I have actually fixed it now and it's working perfectly. I have also used variations of this script all over the place now so thankyou once again it's becoming very handy...

I might just get rid of the session_register lines if they are depreciated code.. Thanks :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove/Hide Div in Javascript Popup markmon Javascript How-To 2 March 24th, 2008 09:10 AM
user logged jonyBravo Access 6 November 27th, 2006 09:14 AM
hide/show <div> saban ASP.NET 2.0 Basics 3 November 21st, 2006 09:53 AM
hide the <div> crmpicco Javascript How-To 1 August 22nd, 2005 09:43 PM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.