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 8546073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:56:04+00:00 2026-06-11T12:56:04+00:00

I wrote this script. It is working, but when I leve the page, or

  • 0

I wrote this script.
It is working, but when I leve the page, or when I return to the page, sessions are not being saved. What I am doing wrong?

login.php

<?php
session_start();
require 'classes.php';

//if user is not yet authorized
if ($_SESSION['user']->iduser == null) {
    $dbhandle = mysql_connect($hst, $usr, $pass);
    if (!$dbhandle) {
        die('Could not connect: ' . mysql_error());
    }
    $selected = mysql_select_db($dbName, $dbhandle)
            or die("Could not select the database");

    $result = mysql_query(" query ");
    $resultArray = mysql_fetch_array($result);
    $num_rows = mysql_num_rows($result); //count how many rows returned
    //if 0 rows returned, then login was failed
    if ($num_rows == 0) {
        die('Error! Access denied. Incorrect username or password.');
    } else { //if username and password match
        $_SESSION['user'] = new user();
        $_SESSION['user']->iduser = $resultArray{'iduser'};
        $_SESSION['user']->fname = $resultArray{'fname'};
        echo 'Dear ' . $_SESSION['user']->fname . ', you succesfully logged in!';
    }
    //if user is already logged in
} else {
    echo 'You already logged in!<br>Your email is: ';
}
?>

class user

<?php
class user {
    public $iduser = null;
    public $fname = null;
    public $lname = null;
    public $email = null;
    public $password = null;
    public $permission = null;
}
?>
  • 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-11T12:56:05+00:00Added an answer on June 11, 2026 at 12:56 pm

    You need to “require (classes.php)” before the session starts.

    (Simple answer 🙂 )

    Reason: the session is decoded when you call session_start. For an object to be unserialized correctly, then the class must be already defined. Ergo you need to define the class before session_start – swapping those two lines around should do it.

    http://php.net/manual/en/oop4.serialization.php

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

Sidebar

Related Questions

I'm working on this page for a photographer. I wrote a jQuery script that
I am trying to write my very first python script. This was working but
hi i have the following page: [here][link removed] the script i wrote is working
Update: I wrote a working script that finishes this job in a reasonable length
I'm doing form validation using a PHP script. I initially wrote this code in
I wrote a facebook application but authentication is not working properly. Despite of googling
I wrote this script which counts occurrences of particular pattern in a given file.
I wrote this script to for a contact form on my website, everything works
$(function(){ $('a').each(function(){ var x=this.href; this.href=www.somesitename.com/filter+this.href; }); }); i wrote the above jQuery script to
I wrote this script to my live search: $(document).ready(function(){ $('input#search').keypress(function(){ $('ul#pacientes_hint').html(); var texto =

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.