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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:19+00:00 2026-05-23T11:55:19+00:00

I have one index.php , one.php file. In one.php i have starting the session

  • 0

I have one index.php , one.php file.

In one.php i have starting the session and setting the session var:

session_start(); 
if(isset($_GET['user'])){
    $_SESSION['user'] = $_GET['user'];
    }
function getUsername(){
  return $_SESSION['user'];
}

Im including one.php in index.php after im calling the function getUsername()
im not starting session in index.php

include_once('one.php');
echo getUsername();

But im not getting the session in index.php. Why ? im passing the the variable as

index.php?user=newuser .

is it not possible to get the session in all pages with out starting session . is it any possible method to get a global variable from any where, if i set it once..?

  • 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-05-23T11:55:20+00:00Added an answer on May 23, 2026 at 11:55 am

    No it is not possible to get the session in all pages without starting session. So basically, you need to follow either of the following two ways:-

    • Start the session in very new page, at the very beginning of the page, without any whitespace characters, using these lines of code:-

    <?php

    session_start();

    // Other Lines of Code

    • Include another common page (common.php) which has the line (session_start(); at the very beginning of that common page) at the beginning in every new page.

    So basically, this particular statement (session_start();) is the heart of using the session.

    Now according to your question, the page “one.php” must be included at the very beginning. So it should be working.

    Hope it helps.

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

Sidebar

Related Questions

I have been tearing my hair with this one for a while. index.php: $(document).ready(function(){
I have one file index.php, I am trying to include splash.php when no variable
So, ok. I have many php files and one index.php file. All files can't
Within my index.php file I have an AJAX function that will call a function
I have the following javascript into a index.php file: <script type=text/javascript> $('.showpics, .showpics2').live('click', function()
I have two file one is index.php another one is dbsubmit.php In my index.php
OK i have 2 files one is index.php and the other is file.html now
The setup: I have a standard .php file (index.php) that contains two includes, one
If I have an index.php file that includes inc/footer.php I would write: include 'inc/footer.php';
I have few import statements in my index.php file. The website is bit slow

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.