Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

session problem

i have a webpage that if a registered user session is set or true let them view the full contents of the page else if a guest session is set or registered let them only view some of the contents on the page...

my problem is separating these out?

at the moment the site works great without try to include guest sessions.

so at the moment if you want to view the full contents of the page, you have to login and to do so you have to become a member... duh!

but what i want now is to allow unregistered users (guest) view the page too, but only some of the material, but if i try viewing the page without been login in, i get "please login"....

how do i overcome this?
ASKER CERTIFIED SOLUTION
Avatar of TeRReF
TeRReF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ellandrd

ASKER

dont really understand - when user registers, i add there details into a DB.

when user logs in, i compare username/password against that in the DB. if true, i register a session contain cid,username, firstname.

then on each page i wish to allow that user to view, i check for session values... like cid or username etc.

in use your solution, im not too sure how i include it....

eg.

main.php

<?php
require('../globals/includes/session.inc.php');
if ($_SESSION['user']->username == 'administrator')
{
   echo "Logged In As ".$_SESSION['user']->firstname." (<a href='../globals/includes/end.php'>Sign Out</a>)";
   // show admin material here
}
else if ($_SESSION['user']->username != 'administrator')
{
   echo "Logged In As ".$_SESSION['user']->firstname." (<a href='../globals/includes/end.php'>Sign Out</a>)";
   // show registered users material here
}
else
{
   echo "Welcome Guest";
   // show non-registered users material here
}
?>


session.inc.php just checks if session was set or not...



anybody?
some more info that might help you find why i have a problem...


session.inc.php file:
===========================================================================
<?php
require('e:\\domains\\q\\quest-recruiting.com\\user\\htdocs\\globals\\classes\\user.classes.php');

session_start();

if(empty($_SESSION["user"]->cid) || $_SESSION['guest'] == false)
{
      ?>
            <script language="javascript">
            top.location.href = "http://www.quest-recruiting.com/globals/includes/end.php?timeOut=1";
            </script>
      <?
}

if(!is_numeric($_SESSION["user"]->cid) || $_SESSION['guest'] == false)
{
      ?>
            <script language="javascript">
            top.location.href = "http://www.quest-recruiting.com/globals/includes/end.php?timeOut=1";
            </script>
      <?
}

$minutes = 20;

if ($_SESSION['guest'] == false || (time() - $_SESSION["timestamp"]) > $minutes*60)
{
      ?>
      <script language="javascript">
      top.location.href = "http://www.quest-recruiting.com/globals/includes/end.php?timeOut=1";
      </script>
      <?
}
else
{
      $_SESSION["timestamp"] = time();
}
?>




index.php (login section)
============================================================================
<?php
require('e:\\domains\\q\\quest-recruiting.com\\user\\htdocs\\globals\\includes\\session.inc.php');

if(isset($_SESSION['user']->cid))
{
      header("Location: main.php");
}

....

// form so user can login...

?>



index.php
======================================================================
<?php
require('e:\\domains\\q\\quest-recruiting.com\\user\\htdocs\\globals\\includes\\db.inc.php');
$link_id = db_connect();

require('e:\\domains\\q\\quest-recruiting.com\\user\\htdocs\\globals\\includes\\session.inc.php');
include_once('e:\\domains\\q\\quest-recruiting.com\\user\\htdocs\\globals\\classes\\usersOnline.class.php');

if (empty($_SESSION['user']->cid))
{
      $_SESSION['guest'] == true;
      $welcome = "Welcome guest!";
}
else
{
      $welcome = (empty($_SESSION['user']->firstname)) ? "Welcome ".$_SESSION['user']->firstname : "Welcome ".$_SESSION['user']->firstname;
}
?>

please i need some help!

Ellandrd
SOLUTION
Avatar of Bernard Savonet
Bernard Savonet
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial