Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:03:56+00:00 2026-06-17T18:03:56+00:00

After it has been confirmed that the user is logged in, how should pages

  • 0

After it has been confirmed that the user is logged in, how should pages only members are allowed to see be shown?

For example

<?php
    start_session();
    if(isset($_SESSION[userLoggedIn]))
        echo 'welcome to the members area!';
    else
        echo 'You must log in first';
?>

OR

<?php
    start_session();
    if(!isset($_SESSION[userLoggedIn]))
        goto notLoggedIn;
?>
    welcome to the members area!
<?php
    notLoggedIn:
        echo 'You must log in first';
?>

OR

<?php
    start_session();
    if(isset($_SESSION[userLoggedIn]))
        include members.html;
    else
        include public.html
?>

I don’t like having too much HTML inside PHP.

When using the include/require solution, how do I make it so people can’t just go access the html file directily? For example include members.html; what’s stopping a user to type in the url ~/members.html? ATM I’m using WAMP but I’m guessing there’s a setting on the server?

EDIT: Ok this is what my plan is: create two directories public and private and make the webroot public. I’m going to have 1 page that checks to see if the user is logged in and if so the value from $_GET[‘destination’] will be used to include the correct page from the private directory. Any pitfalls I haven’t thought of?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:03:57+00:00Added an answer on June 17, 2026 at 6:03 pm

    I don’t like having too much HTML inside PHP.

    Good. Then move your HTML into HTML templates that handle the presentation logic:

     start_session();
     if(isset($_SESSION['userLoggedIn'])){
        require 'public_html/logged_in.php';
    
     }else{
        require 'public_html/public_area.php';
     }
    

    Better yet, create a function that loads these templates, like:

    function load_template($file, array $vars){
      extract($vars);
      unset($file, $vars);
      require func_get_arg(0);
    }
    

    When using the include/require solution, how do I make it so people
    can’t just go access the html file directily?

    A few ways:

    • define a constant in the main script; check if this constant is defined in your template, exit if not
    • or pass a variable to your template that does the same thing
    • or put these templates outside the web root
    • or protect them with .htaccess rules

    I’m assuming here these templates are also PHP scripts. But of course you can also use some kind of templating system on top of PHP, or create your own…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are looking to redirect users to different pages after code has been executed,
The Product Tags tab would only appear after a product has been created. Even
I am attempting to access the HTML of a page after it has been
I wonder why the value of i is 0 after sscanf has been previously
I'm having a problem closing my app after NSSavePanel has been used... If I
How can i change the color of a link after it has been selected,
Is there any way to update a table layout after it has been created?
I'm trying to change the width of a JQuery dialog after it has been
while(1){ //Command prompt char *command; printf(%s>,current_working_directory); scanf(%s,command);<--seg faults after input has been received. printf(\ncommand:%s\n,command);
is it possible to stop the submission of a form,after submit button has been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.