View Full Version : Members only pages
sirborder
08-14-2006, 01:56 AM
I'm trying to make a members only area, but I need to figure out how to make sure the person is logged in before letting them see the page. Any help would be great.
rlemon
08-14-2006, 08:09 PM
when the user logs in set a "Session" variable to store the username / id / whatever and just check that before the page is displayed
Look up writing and reading session variables.
i.e.
if(!isset($_SESSION['UID']))
{
Header("Location: index.php");
}
// page contents
that code will check for the session var "UID" (user id) and if it is not set it will take the user to the index page
another example:
if(isset($_SESSION['UID']))
{
// page contents
}
sirborder
08-14-2006, 09:08 PM
OK, I'm new to PHP. Please explain that in english.
rlemon
08-14-2006, 09:25 PM
http://ca3.php.net/session
Read that link before you proceed.
my example commented
<?php
if(!isset($_SESSION['UID'])) /* checks to see if the $_SESSION variable named UID is set, placing the punctuation (!) infront of the boolean function looks for false instead of true. So in plain english it would translate into: If the variable $_SESSION['UID'] is not set preform the actions below. */
{
Header("Location: index.php"); /* this is a Header call and will change the header output of the file. Setting Location: path/to/page.html will redirect the user to yourdomain.com/path/to/page.html */
}
?>
<!-- Site content you wish to be seen by registered users -->
<HTML>
<head><title>your page title</title>
</head>
<body>
body contents
</body></html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.