Al Kasih
Al Kasih

Reputation: 886

Echo two different page view on the same page

In this case, I am going to echo/print two different page view in the same page, which it depends on whether the user has logged-in or not.

If the users are logged in, they can find all the menus in the page. However, if the user are not logged in, there would be some views I want to hide from them.

The method that I am going to use is:

First: check if the user has login or not (with session), Then: show the page based on the result of the check of session.

And I will use this code:

<?php
session_start();
if(isset($_SESSION['login_id']) && !empty($_SESSION['login_id'])){
   ?> 
      YOUR HTML CODE
   <? 
} else {
   ?> 
      YOUR HTML CODE
   <?}
?>

My question actually is very simple, I just want to make sure, if I use this method, won't it make the page to load slow?

If this will make the page to load to slow, is there a good method for I to achieve this?

Thanks

Upvotes: 1

Views: 84

Answers (2)

worldofjr
worldofjr

Reputation: 3886

It won't make your page slow (any code in the if-else block that isn't processed won't make any difference to the load time).

You might, however, wish to include a separate PHP file with the information you want to display, rather than code it directly into the if-else block. For example;

session_start();
if(isset($_SESSION['login_id']) && !empty($_SESSION['login_id'])){
    include 'loggedin.php';
}
else {
    include 'notloggedin.php';
}

Hope this helps.

Upvotes: 2

satyr607
satyr607

Reputation: 61

Your page load is really going to depend more on the html then this php switch. I have dealt with pages with 30 switches like this on one page load. While not the best practice anymore you likely wont even notice.

Upvotes: 1

Related Questions