Jump to content

Members Only


dean7

Recommended Posts

try one of these maybe im not an expert but but i know some php

 

if ($logged['username'] == '')
{
echo ("Your Not Logged In!"); 
}else{
echo ("Welcome $logged['username']");

 

if ($_SESSION['username'] == '')
{
echo ("Your Not Logged In!"); 
}else{
echo ("Welcome $_SESSION['username']");

Link to comment
https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948282
Share on other sites

<?php


if ($logged['username'] == '')
{

//Put stuff in here the the users who are not logged in will see

echo "Your not logged in ... login now!";


}else{

//Put stuff in here the the users who are logged in will see

$username = $logged['username'];

echo "You are logged in $username welcome to the private area";
?>

<b> You can put html between "? >" and "< ?php" </b>

<?php
}
?>

 

You need to put the content that the logged in user can see between the "else {

 

}"

 

 

Link to comment
https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948287
Share on other sites

ok I just thought of a simpler way of doing this use this code

 


if(isset($logged['username'])) {
$username = $logged['username'];
//Display stuff here that logged in users will see

echo "Welcome to the logged in area $username";

}

 

also post your page code so I can see it

 

-John

Link to comment
https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948291
Share on other sites

When a person logs in, you have to give them a session variable. So, once they've entered a correct username and password, you could do this:

 

$_SESSION['username'] = $username_from_db;

 

Then on protected pages, check to see if the session variable 'username' exists:

 

if(!isset($_SESSION['username'])){
    header('Location: login.php');
    exit;
}

Link to comment
https://forums.phpfreaks.com/topic/179724-members-only/#findComment-948378
Share on other sites

Archived

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.