简体   繁体   中英

Different homepage for logged and logged-out users

I use PHP for my project and need to display different pages for users who logged in and those who are not. One solution is to check if session is set if(isset($_SESSION['id'])) and if it is, include the one page, and if not, include another.

Example: index.php

<?php
    if(!isset($_SESSION)){
        session_start();
    }

    if(isset($_SESSION['id']))
        include 'logged_home.php';
    else
        include 'unlogged_home.php'; 
?>

But I think it's a bad SEO technique since the index file doesn't have any metadata, title, and keywords. I don't think Google would crawl to unlogged_home.php and get all the keywords from there.

What is the best solution to display different content in index.php based on whether the session is set or not?

Thanks!

Include is not a redirect. As far as Google is concerned, you are only serving up one file - index.php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM