Hello i have a problem. i use session for any user that logs In my website. I use the session user id as a variable to show the first page of my site when one presses my website url (www.mywebsite.com) so, if the session user id is empty then returns the header


But i want to use the empty session id to return the pages i want fot the guests not the ones that log in. On header.php i use the header


if(isset($sessionUid) && $sessionUid>0 )

I use that in every .php file i call, BUT as its obvious, every time i try to call a .php file it redirects back to header("location:$url"); Is it another way to call the header? Or another way to call the guest files?

4 Weeks
Discussion Span
Last Post by SimonIoa

Hi simon - not sure if I follow your post - and whether you need a redirection in all cases. Here's a simplified example off the top of my head that uses the index.php page to route all page requests - it's a trick that most MVCs use:

## index page ##

require "../includes/settings.php";
require "../includes/page_manager.php";

## end on index page ##

## page_manager (../includes/page_manager.php) file ##

    $member = true;
    require '../member/header.php';
    $member = false;
    require '../guest/header.php';

//This can vary - depending if you have apache rewrite
$pagename = isset($_GET['page']) ? $_GET['page'] . '.php' : 'index.php';

if(file_exists('../common/' . $pagename)){
    //display common contant - stuff that should be seen by all visitors
    require '../common/' . $pagename;
}elseif($member && file_exists('../member/' . $pagename)){
    //display members only content
    require '../member/' . $pagename;
    //display guests only notice - not sure if this is required though
    //or do a redirect
    require '../member/guestonly.php';
}elseif(!$member && file_exists('../guest/' . $pagename)){
    //display guest page
    require '../guest/' . $pagename;
    //members only notice and display login form
    //or do a redirect
    require '../member/memberonly.php';
    require '../guest/login.php';

require '../common/footer.php';

## end of page_manager ##

So folders:

/common/ all common "views" for content - e.g. "about" or "contact" content
/member/ all member "views" for content
/guest/ all guest "views" for content
/includes/ all non-view files, e.g. for settings and general functions

Serving different content for the same url can be a bit tricky for SEO - but there again, if you have member-only views, then spiders wouldn't see it anyway. There are many ways to skin a cat - this is just one - and yes, it is very bare-bones.

Edited by diafol


OK i solved it thanks diafol. In my case i had to call session_start(); your post reminded me that.

For people who will see this in the future, this post is the answer if you want to use session or not to include files accordingly....

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.