After and Before Login : About PHP & Sessions
Well, after much work, at last, i have created members system. Well its not completed yet, reason is when i open page it works - it can register new peoples, can login but (till my website doesn't have any memberr-only page.) I don't know how to make "Sign Up" button disappear while user has logged-in and show "Log out" and "User Name" instead. Means, IDK how to tell website that user has logged in. I know it is not big deal, i just don't get how... please help me. Hear my codes...
1. This part is at end of my login script....
I think problem is here....
$_SESSION['userName'] = $userName;
echo 'Successfuly logged-in!';
2. This is part of index.php , in that empty division with id "systemTarget", i want to show buttons... like "Sign Up" and "Sign In" if user is not signed in, and "Username" & "Log out" if user isn't signed in.
Hope i am clear, In addition: It would be great if somebody also tells me that how to make some pages "members-only" (if i not get from the answer of above)...! :P
<div id="wrap_h"><img src="images/jsk_logo_pfc.jpg" style="float:left"/><div id="systemTarget"></div>
You'll need some sort of conditional logic in each page where you want the login/sign-out links to appear. This may be a good candidate for something to put into a function so you can call it as/where needed if it will appear on multiple different pages.
// display log-in and sign-up options here
// display log-out option here
Some more help....
can i know what i shall do to logout? And in anywhere shall i include ...
I use this at the top of every page that I'm using sessions on or wanting to carry sessions over on:
and this on the bottom of every page:
"ob" = output buffering, something I personally would not bother with unless you have a specific reason to use it. (It's going to add a little bit of processing/memory overhead which, while probably fairly trivial, why bother if you don't actually need it? (There are valid reasons why you might need it, in which case, no big deal.)
It depends on how you make your website and pages. If you start getting "headers already sent" error messages then you may want to consider using ob_start and ob_end_flush.
If things are well designed and properly configured, you shouldn't get those sorts of errors -- but sometimes if I'm using 3rd-party classes, packages, etc., that are not so well designed, it can be useful to add buffering rather than spending time to fix them.
Originally Posted by Alan P
It can also be useful if you want to compress your output (by using the ob_gzhandler() function as the optional callback parameter in ob_start()).
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread