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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:08:15+00:00 2026-06-06T13:08:15+00:00

I want to access the session variable which I declared in the another php

  • 0

I want to access the session variable which I declared in the another php file.

How can I do that?

Here is what I did.

test.php

$_SESSION['SESS_VERSION'] = $member['Version'];
session_write_close();
header('location: '.$_SESSION['SESS_VERSION']);

This session variable is working and I am correctly redirected to another page.

On that page for example:

test2.php

I am calling a php script from javascript to return me a JSON formated data.

What I was trying to do in that test3.php script is to access a session variables from test.php

Here’s the code:

<?php
header("Content-type: application/json; charset=UTF-8");

echo '{ "results" : [ ';

$result = dbMySql::Exec("SELECT 
    m.data1
    v.data2,
    k.data3
FROM {$_SESSION['SESS_MAIN_BASE']} m, {$_SESSION['SESS_SECOND_BASE']} v, {$_SESSION['SESS_THIRD_BASE']} k");
$result_array = array();
?>

Why I can’t access any of the session variables on this php page? Maybe my syntax is not correct. But this is the error that I am getting:

Warning: Cannot modify header information - headers already sent 

And of course error that variables are empty.

  • 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-06T13:08:16+00:00Added an answer on June 6, 2026 at 1:08 pm

    you need

    session_start()

    at the top of each of your php scripts otherwise the session variable is meaningless across php files.

    Also you are getting the Cannot Modify header error because you have

    Here’s the code:

    being sent to the browser before the headers, move all header functions before any content

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

Sidebar

Related Questions

I have a main page that starts a PHP session, which creates session ID
I want to access a session variable from my layout master page, but you
How to access PHP session variables from jQuery function in a .js file? In
I want to access PHP session variables through jQuery. What is the best way
When I use session variable for a website in PHP, is that information stored
How can I access session variable from the HttpModule ? I set following session
I want to access java script's return value , which in is in a
I want to access a static variable from a static method: #!/usr/bin/env python class
I want to add my own session variable to elmah error log table and
I did read manuals about access to current user via everyauth. It's say, that

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.