Results 1 to 3 of 3

Thread: How to display custom home pages to logged in users?

  1. #1
    Join Date
    Jun 2014

    How to display custom home pages to logged in users?

    I am a beginner in PHP programming.How can I create custom home page for logged in users. For example, facebook displays the content based on the user log in. Every url reads www.facebook.com but the content varies on who has logged in. I do not have any idea of how to do this, so any basic help or referring related articles would be of great help.

  2. #2
    Join Date
    Aug 2004
    It's a coordination between your database and your login system. Typically upon a successful login, the user's unique ID is stored in session data. You can then query the database for applicable items that use that ID as a (foreign) key. E.g.: rows in a status_update DB table would include the user_id as one of the fields.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    We have a Moodle site (running 2.2.2) that will be selling courses and would like to be able to display "marketing" information before a student joins or logs in -- and would prefer to do this at the same URL (i.e. the same homepage). I saw a lot of posts about customizing the homepage AFTER login but nothing about before.

    After thinking this through it seemed pretty straightforward to solve. I just created a simple login check and redirect. But given my limited PHP knowledge I thought I would post my solution here to see if the community could confirm my approach or suggest a better approach for me.

    In /Index.php I added the following code after ~lines 70 where we get our first login status check (my additions in bold):

    if (isloggedin()) {
    add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);

    ///Redirect to the custom homepage if they're not logged in
    if (!isloggedin()) {
    redirect($CFG->wwwroot .'/home.html');

    /// If the hub plugin is installed then we let it take over the homepage here
    if (get_config('local_hub', 'hubenabled') && file_exists($CFG->dirroot.'/local/hub/lib.php')) {
    $hub = new local_hub();
    $continue = $hub->display_homepage();
    //display_homepage() return true if the hub home page is not displayed
    //mostly when search form is not displayed for not logged users
    if (empty($continue)) {

    So far it seems to be working really well. My custom homepage located at /home.html has login functionality that works seamlessly to allow existing users to login to the site. Once logged in you never see the marketing homepage, even when clicking back to "home."

    I just want to make sure this is the best way to tackle this -- and the best place for the code in /Index.php. It's obviously an important bit.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center