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

  • Home
  • SEARCH
  • 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 8789915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:31:42+00:00 2026-06-13T22:31:42+00:00

I am a first time php developer; I track sessions this way: session_start(); if

  • 0

I am a first time php developer;

I track sessions this way:

session_start();
if (!isset($_SESSION['user']->iduser)) {
    die('Access denied. <br><a href=login.php>Please login</a>');
}

is that correct approach?

  • 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-13T22:31:43+00:00Added an answer on June 13, 2026 at 10:31 pm

    Your code makes it seem as though you’re storing an entire object into a session-variable which would not be a great idea (could take up a lot of space, stores way too much data, is it even possible without serialize/unserialize?).

    Also, if your user hasn’t been authenticated yet your code would throw a warning because $_SESSION['user'] isn’t set yet – so by checking for $_SESSION['user']->iduser, you’d be checking for a property/value on a null object. Your code should check if (isset($_SESSION['user'])) {, and then possibly validate on that.

    I would recommend just storing the “essentials” in the session such as the user’s ID/username and encrypted password. Then, during each page load you re-validate the information against the database. It’s an extra query on each page-load, but it’s worth it (in my opinion).

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

Sidebar

Related Questions

<?php session_start(); if(isset($_POST['sessionNum'])){ //Declare my counter for the first time $_SESSION['initial_count'] = $_POST['sessionNum']; $_SESSION['sessionNum']
when I run this code for the first time <?php session_start(); echo SID; ?>
this is my first time to work with API's in PHP, so please bear
Long time mysql/php user, first time Drupal user. Actually, I'm not doing the Drupal
I am new to PHP-> first time developer. I am working on my web
I've been working with json for the first time and php for the first
I have started using PDO in php for the first time. Here is my
I'm using Dynatree for the first time and wrote a PHP script that returns
I was asked to perform(first time) a task in PHP with PostgreSQL for the
This is my first post and I'm not really a developer (more an enthusiastic

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.