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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:38:51+00:00 2026-06-15T02:38:51+00:00

I have a problem when setting sessions, when I set a: $_SESSION[predefinedvar] = SOMETHING

  • 0

I have a problem when setting sessions, when I set a:
$_SESSION[“predefinedvar”] = “SOMETHING”
It will remember the session variable, but however, when I do a:
$_SESSION = $class->somearray;
It won’t save the session array.

I have searched the web, and tried the first few pages from Google from this search:
php session assign array

The output is similar to this when I do an print_r($_SESSION) or print_r($l->details);
This is the output the script gives me (both from $_SESSION and $l->details)

Array
(
    [1] => Array
        (
            [id] => 1
            [username] => Usernamehere
            [password] => EnCryptedPasswordHere
            [mail] => em@il.com
            [ip] => ::1
            [registerred] => 1349111531
            [loggedin] => 0
            [vip] => 0
        )

    [2] => Array
        (
            [id] => 1
            [city] => 1
            [family] => 0
            [pm] => 0
            [mod] => 0
        )

    [3] => Array
        (
            [id] => 1
            [url] => images/pb/1.png
        )

    [4] => Array
        (
            [id] => 1
            [rank] => 1
            [subrank] => 5000
        )

    [5] => Array
        (
            [id] => 1
            [hp] => 100
            [str] => 0
            [def] => 0
        )

    [6] => Array
        (
            [id] => 1
            [money] => 0
            [bank] => 0
            [bullets] => 0
            [points] => 0
        )

)

Currently I have the following codes

login.c.php

<?php
if(!$required) die("Du har ikke adgang til denne filen.");

class login {

    var $username, $password;
    var $details;
    var $salt = "SALTHIDDEN";
    var $error;
    var $justcheck;

    function onPost($username, $password, $justcheck = FALSE) {
        if($justcheck) $this->justcheck = $justcheck;
        if(!$username || !$password) die("Du må skrive inn både brukernavn og passord.");
        $this->username = htmlspecialchars(addslashes($username));
        $this->password = sha1(md5($this->salt . $password));
    }

    function checkDetails() {
        $query = mysql_query("SELECT * FROM users WHERE username = '".$this->username."' AND password = '".$this->password."' LIMIT 1");
        $num = mysql_num_rows($query);
        if($num > 0) {
            $this->details[1] = mysql_fetch_assoc($query);
            return TRUE;
        }
        else {
            $this->error[] = "Feil brukernavn eller passord.";
            return FALSE;
        }
    }

    function getEverything() {
        $this->details[2] = mysql_fetch_assoc(mysql_query("SELECT * FROM user_c WHERE id='".$this->details[1][id]."' LIMIT 1"));
        $this->details[3] = mysql_fetch_assoc(mysql_query("SELECT * FROM user_p WHERE id='".$this->details[1][id]."' LIMIT 1"));
        $this->details[4] = mysql_fetch_assoc(mysql_query("SELECT * FROM user_r WHERE id='".$this->details[1][id]."' LIMIT 1"));
        $this->details[5] = mysql_fetch_assoc(mysql_query("SELECT * FROM user_s WHERE id='".$this->details[1][id]."' LIMIT 1"));
        $this->details[6] = mysql_fetch_assoc(mysql_query("SELECT * FROM user_i WHERE id='".$this->details[1][id]."' LIMIT 1"));
    }
    function returnValue() {
        if($this->error) foreach($this->error as $e) echo "$e<br />";
        if(!$this->justcheck && !$this->error) die("<a href=\"#main\">Du er nå innlogget som $username<br />Klikk her hvis du ikke viderekobles til hovedkvarteret.</a><meta http-equiv=\"Refresh\" content=\"0; url=#main\">");
    }

}

and this file is the POST.php file:

<?php

require_once("path/hidden/db.php");

switch(key($_GET)) {
    default:
        echo "Nothing to do here";
    break;

    case "login":
        $required = TRUE;
        require_once("path/hidden/login.c.php");
        session_start();
        $l = new login();
        $l->onPost($_POST["username"], $_POST["password"]);
        if($l->checkDetails()) {
            $l->getEverything();
            session_start();
            $_SESSION = $l->details;
        }
        $_SESSION[RandomVar] = "RandomVal";
        //$l->returnValue();
        print_r($_SESSION);
        print_r($l->details);
        //echo session_id();
    break;
}
  • 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-15T02:38:53+00:00Added an answer on June 15, 2026 at 2:38 am

    You need to assign a name for the Session variable. You tried the following:

     $_SESSION = $class->somearray
    

    But you need to assign a key for your array:

    $_SESSION['my_array'] = $class->somearray
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem... I want to set a session variable when clicking
I have tried setting cookies but the problem is in setting domain. When i
OK, I have a problem. I'm setting up a site that will end up
Weired problem! ASP.NET Session expires instantly. In my web.config I have this session settings:
I have problem with setting proper charset on my jsf pages. I use MySql
I have a problem with setting the HTTPBody of a request correctly. I'm using
I have a problem with setting Browsing Path in Delphi 2009: When I install
I have this weird problem with setting up cookies with PHP. Everything worked fine
i have problem to correctly bind data to WPF Chart. When i'm setting ItemsSource
I have a weird problem where after setting nocheck on a foreign constraint and

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.