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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:36:03+00:00 2026-05-20T19:36:03+00:00

I have observed my php application behaving rather strangely on the server that it

  • 0

I have observed my php application behaving rather strangely on the server that it is running on. When a user first visits the application, and clicks on a link with an absolute path, the session data is cleared.

I have recreated the problem as simply as possible. The code can be found below.

I have solved this problem by removing all absolute links in my application, I am simply looking for an explanation of this behavior.

To recreate the problem:

  1. click ‘login’
  2. click ‘relative link’ and observe that the session still has the ‘logged_in’ variable set
  3. click ‘absolute link’ and observe that the session data appears to be missing
  4. click your browser’s back button and observe that the session data has returned
  5. click ‘absolute link’ and observe that the session data is missing again
  6. click ‘home (relative link)’ and observe that session data is missing this time
  7. click ‘login’ to reset the session data
  8. click ‘absolute link’ again and observe that the session data was not cleared this time

Some important things to note:

  • This is not a problem locally on my
    mac running MAMP with php 5.3.2,
    but is a problem on a server with
    php 5.2.14 and a different server running 5.3.2
  • clicking the absolute link, and then the relative home link without login prevents the problem from ever occurring once you do log in.
  • once the problem is solved by the method just mentioned, it can only be recreated by navigating to a different domain, clearing your browser’s cache and navigating back. Clearing the cache without leaving the page will not work.
  • this is also a problem if using a absolute path when redirecting using header(‘Location: …’)

index.php:

<?php
    session_start();

    print_r($_SESSION);

?>

    <br/><a href="http://www.myserver.org/page.php">Absolute link</a>
    <br/><a href="page.php">Relative link</a>
    <br/><a href="login.php">Log in</a> | <a href="logout.php">Log out (reset session)</a>

page.php:

<?php

    session_start();
    print_r($_SESSION);

?>
    <br/><a href="index.php">Home (relative link)</a>

login.php:

<?php
    session_start();
    $_SESSION['logged_in'] = true;

    header('Location: index.php');

logout.php:

<?php
    session_start();

    $_SESSION = array();
    session_destroy();

    header('Location: index.php');
  • 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-20T19:36:04+00:00Added an answer on May 20, 2026 at 7:36 pm

    Solved:
    Thanks to Nouveau for pointing out that a cookie can only be used for one domain and The Scrum Meister for asking if I always access the site with a www.

    The problem was created by starting at http://myserver.com and following the link to http://www.myserver.com

    The Session was initialized for http://myserver.com and then again for http://www.myserver.com

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

Sidebar

Related Questions

I have a few questions about sessions and login/logout systems. In my system, first
I know from what I have observed, and from what people are saying on
I'm currently working on a logging solution for one of our web projects. Server
First of all, thanks so much to everyone who has helped me on this
I have a dropdownlist ddlTables which contains the table names in my database and
I am just starting to work with native encryption in SQL Server, and I
We are having a performance problem in our application - particularly when the browser
I've written an application to easily connect Android devices to our company's various wireless
I would like to set the default number of displayed rows in the admin

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.