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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:30:29+00:00 2026-06-11T08:30:29+00:00

On File A.php I have a while Loop that pulls data from a database

  • 0

On File A.php I have a while Loop that pulls data from a database and connects to class.php to create objects for each dataset. That part works fine.
Within that Loop I try to save each object to a SESSION defined by its id value
after New Object has been created

File A.php:

$_SESSION[$pObject->id] = $pObject;

if (isset($_SESSION[$pObject->id]))

{

echo "SESSION $pObject->id is set"; 

}

I have confirmed that it IS being created.

NOW, I have a form that sends an Objects id value via a GET to File B.php, I have confirmation that the value is received.

File B.php:

require_once 'class.php';

session_start();

$id = $_GET['id'];

echo $id;

//Now $id is in my new file, so I try to call my SESSION

if(isset($_SESSION[$id]))

{

echo "SESSION $id is set";

$pObjectCurrrent = $_SESSION[$id];

}

else{

echo "SESSION $id is Not set";

}

The issue is, that despite $id in File B.php being equal to the value of $pObject->id in File A.php the SESSION[$id] in File B.php is NOT set and has no value. Instead I receive an undefined variable error. Any ideas would be greatly appreciated.

  • 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-11T08:30:31+00:00Added an answer on June 11, 2026 at 8:30 am

    You can’t use an integer as your session variable name.

    You could set the session var like this:

    $_SESSION['obj' . $pObject->id] = $pObject;
    

    Then retrieve it from B.php like this:

    echo $_SESSION['obj' . $id];
    

    Essentially that concatenates the ID with a string so the variable name would be “obj5”, “obj2”, etc.

    Also – if you’re passing a lot of data in session objects, I’d recommend researching serializing and alternatives like storing session data to DB.

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

Sidebar

Related Questions

I have a PHP form that pulls data from the database, prints it out
I have a file ajax.php that needs to trigger a big while loop and
I have a php file which checks for login and password from users database,
I have created a while loop that selects random images from from my server
So I have an array that gets created from a php loop that looks
I have a while loop issue in PHP that seems like it could have
I have a PHP file that contains a large array (about 90KB). I'm considering
i have a php file which stores a variable, and i need to create
I have a php file setup to pull through ONE XML data feed, What
So I have a php file that retrieves some variables with the $_GET method

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.